Simple Tkhtml web page displayer

Purpose: to provide Neil Madden's five line Tkhtml based web page displayer [L1 ].

This app fetches a web page, formats it, and displays it in a tk scrollable widget. It currently does not handle redirecting URLs, making the web pages active, or ease of changing fonts, etc.

Perhaps some variant of this would be a useful proc for tklib.

Also see the One-line web browser in Tcl

(Hopefully this should display ok now)


package require Tkhtml;package require http;pack [scrollbar .vsb \
 -orient vertical -command {.html yview}] -side right -fill y;pack \
 [html .html -bg white -yscrollcommand {.vsb set}] -fill both \
 -expand 1;set t [http::geturl https://wiki.tcl-lang.org/976];.html \
 parse [http::data $t];http::cleanup $t

(it was something like that anyway - can't remember exactly where the linebreaks were - NEM)


A much more readable version for those just interested in a quick look:

package require Tkhtml
package require http
pack [scrollbar .vsb -orient vertical -command {.html yview}] -side right -fill y
pack  [html .html -bg white -yscrollcommand {.vsb set}] -fill both -expand 1
set t [http::geturl https://wiki.tcl-lang.org/976]
.html parse [http::data $t]
http::cleanup $t

Latest and greatest (thanks to DKF and others for comments). No -bg white, but fits in 4 lines/80 chars and adds hyperlinks and error handling (ignoring)!:

package r Tkhtml 2;package r http;pack [scrollbar .v -o v -co {.h yv}] -s right \
 -f y;pack [html .h -ys {.v set}] -f both -e 1;bind .h.x <1> {eval g [.h href %x\
 %y]};proc g u {set t [http::geturl $u];.h cl;.h p [http::data $t];http::cleanup\
 $t;.h co -base $u};g https://wiki.tcl-lang.org/976;proc bgerror args {};# NEM :-)

LV 2007 June 05 - I updated the code above to specify Tkhtml 2. There are several changes in Tkhtml that make the example non-functional.


NEM - Redirecting URLs aren't too hard. See Following Redirects for a solution.


A rudimentary package which adds some extra functionality (image handling etc) is available at [L2 ] although the author (NEM) hasn't touched it for a while (see snitbrowser below for something newer).


DDG 13 Nov 2003 This is slightly longer as a oneliner but it is inspired by code on this page (thx). A Snit wrapper widget created as a one afternoon hack. It's named snitBrowser because the TclPlugin contains already a package named browser! May be it is long but as a result the widget is fully reuseable. So easy is Snit's Not Incr Tcl ....! The Code is now on its on page: snitbrowser!


escargo 13 Nov 2003 - I found this did not wrap lines in formatted text; is that the way it's supposed to work?

DDG 14 Nov 2003 I think this is fixed in the new version 0.2 see snitbrowser.


See also