Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:

#!/usr/bin/wish

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., 2024: 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