From: Alexandre F. <ale...@gm...> - 2010-12-09 13:48:51
|
On Thu, Dec 9, 2010 at 2:18 PM, Rene Zaumseil <r.z...@fr...> wrote: > Am Thursday 09 December 2010 13:45:58 schrieb Alexandre Ferrieux: >> trace variable v w {$w configure -state $v;list} > % button .b -text ddd > .b > % grid .b > % trace add variable v w {.b conf -state $v;list} > bad operation "w": must be array, read, unset, or write Huh sorry, a bit over-optimistic about prefix-completion ;-) > % trace add variable v write {.b conf -state $v;list} > % set v disabled > disabled > % destroy .b > % set v normal > can't set "v": invalid command name ".b" > > So you have to be carefull to remove the created traces. > -statevar is in the widget and goes away for free. Yes, that was just the principle. But it is still doable in script: proc bindstate {w v} { if {[info exists ::statevar($w)]} { set ov $::statevar($w) trace remove variable $ov write "$w configure -state \$$ov;list" } if {$v==""} { unset ::statevar($w) trace remove command $w delete "bindstate $w {};list" return } trace add variable $v write "$w configure -state \$$v;list" trace add command $w delete "bindstate $w {};list" set ::statevar($w) $v } # Example using it: pack [button .b -text Button] pack [checkbutton .c -text CheckButton] bindstate .b ::s1 bindstate .c ::s2 after 2000 {set s1 disabled;destroy .c} after 4000 {set s2 disabled} after 6000 {set s1 [set s2 normal]} # remove the ";destroy .c" to see the normal sequence. -Alex |