Posted to tcl by teo at Wed Jul 23 14:12:32 GMT 2014view raw
- package require Itcl
- itcl::class bar {
- public {
- method config_textvar {w var} {
- $w configure -textvariable [itcl::scope $var]
- set $var [clock seconds]
- }
- }
- private {
- variable foo 0
- variable bar 0
- }
- }
- itcl::class foo {
- constructor args {
- create
- }
- public {
- method create {} {
- set obj_ [uplevel \#0 bar \#auto]
- pack [frame .f] -fill both -expand yes
- pack [button .f.a] [button .f.b] [button .f.c] [button .f.d] -fill both -expand yes
- switch -- $count_ {
- 0 {
- $obj_ config_textvar .f.a foo
- .f.b configure -textvariable [itcl::scope count_]
- }
- 1 {
- $obj_ config_textvar .f.b foo
- .f.c configure -textvariable [itcl::scope count_]
- }
- 2 {
- $obj_ config_textvar .f.c foo
- .f.a configure -textvariable [itcl::scope count_]
- }
- }
- after $interval_ms_ [itcl::code $this assign]
- }
- method assign {} {
- incr count_
- if {$count_ > 2} { set count_ 0 }
- set foo_ $count_
- after $interval_ms_ [itcl::code $this remove]
- }
- method remove {} {
- rename $obj_ {}
- destroy .f
- unset foo_
- after $interval_ms_ [itcl::code $this create]
- }
- }
- private {
- variable interval_ms_ 100
- variable count_ 0
- variable foo_ 0
- variable obj_ {}
- }
- }
- wm geometry . 200x200
- update idle
- foo .foo