Purpose: some gentle introductory examples of Tk
#! /usr/local/bin/wish8.1 button .hello -text "Hello, World!" -command { exit } pack .hello
These two lines place a clickable button on the screen, labeled "Hello, World", and the application terminates when the button is clicked.
Here's a slightly more useful variation: the button displays a counter that is incremented every time the button is clicked:
#! /usr/local/bin/wish8.1 button .b -text 0 -command {.b config -text [expr [.b cget -text]+1]} pack .b ;#RS
The explanation of the second example is this:
JDG: Here's a different approach to the second example---it uses the -textvariable arg:
set foo 0 button .b -textvariable foo -command { incr foo } pack .b
Again, a different approach---useful under different circumstances (I find myself using -textvariable a *LOT* ... that's why I threw this in). --jdg RS: You're right, this is better. I considered it too but wanted to write a one-liner - until I saw that I'd need the #! line too... Point taken.
KBK: If you ever encounter a system in which the #! line doesn't work, then try the following (for explanation, see exec magic):
#! /bin/sh # next line is executed by the shell, but a comment in tcl \ exec /path/to/wishM.N "$0" ${1+"$@"} set foo 0 button .b -textvariable foo -command { incr foo } grid .b
If the #! doesn't work, then it is unlikely that the above trick will work either. On the other hand, if #! does work , but the path to the wish is so long that it is causing some heartburn to your shell, then the above mentioned trick works.
However, that seems out of context for this page...