Posted to tcl by CecilWesterhof at Thu Jun 28 10:19:59 GMT 2018view raw
- #!/usr/bin/env tclsh
- package require Tk
- set brewLen 7
- set viewLen 10
- wm resizable . 0 0
- wm title . "Tea Application"
- ttk::notebook .nb
- option add *Listbox.font TkFixedFont
- frame .f1
- listbox .f1.brew \
- -exportselection 0 \
- -height ${brewLen} \
- -selectmode single \
- -width 40
- bind .f1.brew <Double-1> {makeTea %W}
- listbox .f1.latest \
- -exportselection 0 \
- -height ${brewLen} \
- -state disabled \
- -width 40
- button .f1.btn -text Refresh -command refreshTeaList
- grid .f1.brew .f1.latest .f1.btn
- grid .f1.btn -row 1 -column 0 -columnspan 2 -pady 10
- frame .f2
- listbox .f2.inStock \
- -exportselection 0 \
- -height ${viewLen} \
- -state disabled \
- -width 40
- button .f2.btn -text Refresh -command refreshTeaInStock
- grid .f2.inStock .f2.btn
- frame .f3
- listbox .f3.outStock \
- -exportselection 0 \
- -height ${viewLen} \
- -state disabled \
- -width 40
- button .f3.btn -text Refresh -command refreshTeaOutStock
- grid .f3.outStock .f3.btn
- frame .f4
- listbox .f4.allTeas \
- -exportselection 0 \
- -height ${viewLen} \
- -state disabled \
- -width 40
- button .f4.btn -text Refresh -command refreshTeaAll
- grid .f4.allTeas .f4.btn
- .nb add .f1 -text "Brew Tea"
- .nb add .f2 -text "In Stock"
- .nb add .f3 -text "Out Stock"
- .nb add .f4 -text "All Teas"
- 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.