Posted to tcl by teo at Wed Jul 23 14:12:32 GMT 2014view raw

  1. package require Itcl
  2.  
  3. itcl::class bar {
  4. public {
  5. method config_textvar {w var} {
  6. $w configure -textvariable [itcl::scope $var]
  7. set $var [clock seconds]
  8. }
  9. }
  10. private {
  11. variable foo 0
  12. variable bar 0
  13. }
  14. }
  15.  
  16. itcl::class foo {
  17. constructor args {
  18. create
  19. }
  20.  
  21. public {
  22. method create {} {
  23. set obj_ [uplevel \#0 bar \#auto]
  24. pack [frame .f] -fill both -expand yes
  25. pack [button .f.a] [button .f.b] [button .f.c] [button .f.d] -fill both -expand yes
  26. switch -- $count_ {
  27. 0 {
  28. $obj_ config_textvar .f.a foo
  29. .f.b configure -textvariable [itcl::scope count_]
  30. }
  31. 1 {
  32. $obj_ config_textvar .f.b foo
  33. .f.c configure -textvariable [itcl::scope count_]
  34. }
  35. 2 {
  36. $obj_ config_textvar .f.c foo
  37. .f.a configure -textvariable [itcl::scope count_]
  38. }
  39. }
  40. after $interval_ms_ [itcl::code $this assign]
  41. }
  42. method assign {} {
  43. incr count_
  44. if {$count_ > 2} { set count_ 0 }
  45. set foo_ $count_
  46. after $interval_ms_ [itcl::code $this remove]
  47. }
  48. method remove {} {
  49. rename $obj_ {}
  50. destroy .f
  51. unset foo_
  52. after $interval_ms_ [itcl::code $this create]
  53. }
  54. }
  55. private {
  56. variable interval_ms_ 100
  57. variable count_ 0
  58. variable foo_ 0
  59. variable obj_ {}
  60. }
  61. }
  62.  
  63. wm geometry . 200x200
  64. update idle
  65. foo .foo
  66.