Updated 2003-09-22 18:34:05

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.

dgp writes:
 >package require -exact Tk $::tcl_version

  I would not recommend that.  In fact, I'd recommend against it.

  Your scripts ought to be using [package require] to record their
  own dependencies.  What you have above is an attempt to encode Tk's
  dependency on the same version of Tcl.  That's not your job.  Tk can
  take care of itself.

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'

 proc shutdown {} {
        # perform necessary housework for ensuring that application files
        # are in proper state, lock files are removed, etc.
 }

 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.

What should one put into the application to enable use of various languages?

[I would presume this question is talking about human languages - and is not wish specific, but relevant to any tcl application.]

Category Example | Category GUI