Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Defining events including variable values in Tk

With Tcl/Tk, you assign an action to a button when you define the button. The action is often specified by the -command option, and it's important to understand the difference between double quotes and braces in this context.

If you put the command in DOUBLE QUOTES, then any $ variable used within the command that's to be run will be interpreted using the variable's value at the time that the button is DEFINED.

If you put the command in CURLY BRACES, then any $ variable used within the command that's to be run will be interpreted at the time that the button is PRESSED.

For example:


proc action {ff ss} {
    puts "$ff and $ss"

for {set k 1} {$k<5} {incr k} {
    button .first$k -text "First $k" -command "action one $k"
    button .second$k -text "Second $k" -command {action two $k}
    pack .first$k .second$k
set k 7

All the buttons with "First" text will give different results when pressed - from 1 to 4. The buttons with "Second" text will all give the result 7 when pressed as that's the value that's been left in the variable k when the tcl/tk process enters its main loop.

earth-wind-and-fire:~/feb05 grahamellis$ wish wishdemo
one and 1
two and 7
one and 2
two and 7
one and 3
two and 7
one and 4
two and 7
earth-wind-and-fire:~/feb05 grahamellis$

See also Tk Events

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Tcl/Tk - Events in Tk
  [386] - ()
  [1473] - ()
  [3575] - ()
  [4258] - ()

resource index - TclTk
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/tcl-defi ... in-tk.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard