Posted to tcl by CecilWesterhof at Thu Jun 28 10:19:59 GMT 2018view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. package require Tk
  4.  
  5.  
  6. set brewLen 7
  7. set viewLen 10
  8.  
  9. wm resizable . 0 0
  10. wm title . "Tea Application"
  11. ttk::notebook .nb
  12. option add *Listbox.font TkFixedFont
  13.  
  14. frame .f1
  15. listbox .f1.brew \
  16. -exportselection 0 \
  17. -height ${brewLen} \
  18. -selectmode single \
  19. -width 40
  20. bind .f1.brew <Double-1> {makeTea %W}
  21.  
  22. listbox .f1.latest \
  23. -exportselection 0 \
  24. -height ${brewLen} \
  25. -state disabled \
  26. -width 40
  27.  
  28. button .f1.btn -text Refresh -command refreshTeaList
  29.  
  30. grid .f1.brew .f1.latest .f1.btn
  31. grid .f1.btn -row 1 -column 0 -columnspan 2 -pady 10
  32.  
  33. frame .f2
  34. listbox .f2.inStock \
  35. -exportselection 0 \
  36. -height ${viewLen} \
  37. -state disabled \
  38. -width 40
  39.  
  40. button .f2.btn -text Refresh -command refreshTeaInStock
  41.  
  42. grid .f2.inStock .f2.btn
  43.  
  44. frame .f3
  45. listbox .f3.outStock \
  46. -exportselection 0 \
  47. -height ${viewLen} \
  48. -state disabled \
  49. -width 40
  50.  
  51. button .f3.btn -text Refresh -command refreshTeaOutStock
  52.  
  53. grid .f3.outStock .f3.btn
  54.  
  55. frame .f4
  56. listbox .f4.allTeas \
  57. -exportselection 0 \
  58. -height ${viewLen} \
  59. -state disabled \
  60. -width 40
  61.  
  62. button .f4.btn -text Refresh -command refreshTeaAll
  63.  
  64. grid .f4.allTeas .f4.btn
  65.  
  66. .nb add .f1 -text "Brew Tea"
  67. .nb add .f2 -text "In Stock"
  68. .nb add .f3 -text "Out Stock"
  69. .nb add .f4 -text "All Teas"
  70. pack .nb

Comments

Posted by emiliano at Thu Jun 28 12:22:15 GMT 2018 [text] [code]

you can refactor the last three tabs in a loop, as follows: foreach tab {"Tea In Stock" "Tea Out Stock" "All Teas"} \ cmd {refreshTeaInStock refreshTeaOutStock refreshTeaAll} { set f .f[string map {" " ""} $tab] frame $f listbox $f.lb button $f.btn -text Refresh -command $cmd grid $f.lb $f.btn }

Posted by CecilWesterhof at Thu Jun 28 15:03:24 GMT 2018 [text] [code]

I have done that. Thanks. I also changed the refresh function. When I want to refresh a tab, I should also refresh the other two. So I got rid of the cmd variable and use refreshAll.