Version 5 of wish application template

Updated 2003-01-30 17:51:43

This template code is for starting a typical wish application.

 #! /bin/sh
 # the next line restarts using wish \
 exec wish "$0" ${1+"$@"}

 package require -exact Tk $tcl_version

This is a little more sophisticated than the code suggested on the tclsh man page (see tcl), and is explained in great detail on exec magic.


The [package require] above will always force the version of Tcl and Tk to be the same. For many years these two packages have been in lockstep release, but there's not rule that says they must remain so.

It's better for you to determine what release of Tk your code needs, and then [package require Tk $yourRequirement]. For example, if you need to use a panedwindow widget, then [package require Tk 8.4].

I hope the example will above will be changed after reading this advice.


As long as there are separately built wishes... The future has already begun since 8.4, and the following command is mandatory for Starkits, or if you always want to start a tclsh first:

 package require Tk ;#8.4 if you so 'wish'

 wm protocol . WM_DELETE_WINDOW { shutdown }

I highly recommend adding this line to any wish template, it insures your shutdown procedure (or any other procedure you wish to call) is invoked when the user clicks on the X icon in the window titlebar. A well-behaved program will shutdown and exit cleanly when this happens. Category Example