Thread

Posted on Tue Mar 25 13:13:07 2008 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 Tue Mar 25 14:10:05 2008 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 Wed Mar 26 07:19:32 2008 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 Wed Mar 26 10:20:49 2008 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
Write a response