Posted on 2008-03-25 11:13:07-07 by dota
a small tk program problem
#!/usr/bin/wish set aa 0 for {set i 1} {$i < 5} {incr i} { set bt [button .$i -text $i] bind $bt <Button-1> { incr aa $bt configure -text $aa update } }
when I press button .1 .2 .3 .4 , only button .4 text change. why this happen ? and how to make button text change separately?
Direct Responses: 7453 | Write a response
Posted on 2008-03-25 12:10:05-07 by vkon in response to 7451
Re: a small tk program problem
your tcl code do variable substitution at the wrong time. try this:
set aa 0 for {set i 1} {$i < 5} {incr i} { set bt [button .$i -text $i] pack .$i bind $bt <Button-1> " incr aa $bt configure -text \$aa update " }
Direct Responses: 7457 | Write a response
Posted on 2008-03-26 05:19:32-07 by dota in response to 7453
Re: a small tk program problem
thanks vkon, this way works well and i found the another way also work:
#!/usr/bin/wish set aa 0 for {set i 1} {$i < 5} {incr i} { set bt [button .$i -text $i] bind $bt <Button-1> { incr aa %W configure -text $aa update } }
what's the difference between "" and {} used in bind command?
Direct Responses: 7459 | Write a response
Posted on 2008-03-26 08:20:49-07 by vkon in response to 7457
Re: a small tk program problem
"" do $variables interpolation (like perl) whereas {}-strings do not do variable interpolation. See "seven tcl rules" wiki.tcl.tk for explanations on this
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.