Version 3 of Using Tk as a loadable package

Updated 2001-10-24 13:03:30

Starting with version 8.3.4 Tk can be loaded dynamically from a tclsh and automatically enters the event loop. The plain Tk8.3.4 is still missing a pkgIndex.tcl file, so for now one has to load tk by hand:

 load libtk8.3.so

This works for Linux. Please add the correct commands for other platforms.

Once Tk does ship with a propper pkgIndex.tcl, it will be loadable platfrom independently with:

 [package require Tk]

The possibility to load Tk on the fly opens up some interesting possibilities. For example one can start a tclsh outide of an X session and later load Tk into it to connect to an X server:

 # start a tclsh that doesn't know anything about X
 $ DISPLAY="" tclsh

 # prove that the display really isn't availible
 % package require Tk
 couldn't connect to display ""
 # now tell it about the display and try loading Tk again.
 % set argv {-display :0}
 -display :0
 % package require Tk
 8.3
 # A window pops up - we have succeeded.

By using subinterpreters, it is even possible to have Tk sessions to different displays at the same time while having no Tk at all in the master interpreter: