I am starting to work with GUI and am using a ttk:notebook. Code at
the end of the post.
I create a notebook with two tabs. The first is just a dummy to get
two tabs.
The seconds is to select a tea. (It should be a table, but that is a
next step.)
The problems I have:
- The first tab has six entries and the second only three. But the
second shows six entries and when I click on one of the empty
entries the last one (Herfst) is selected.
- If I go to the second tab, select an entry, go to the first tab and
select an entry there, makeTea is called and I get the following
error:
missing value to go with key
missing value to go with key
while executing
"dict with tea {
puts "brew ${Tea}, from ${Location}"
}"
(procedure "makeTea" line 4)
invoked from within
"makeTea {{Tea Duizendblad LastUsed 2018-06-15 Location 9} {Tea {Moul Ataï} LastUsed 2018-06-15 Location 12} {Tea Herfst LastUsed 2018-06-15 Location ..."
(command bound to event)
This does not happen before I go to the second tab, or if I go to
the second tab and return to the first without selecting something.
What is happening and how do I solve it?
The code:
#!/usr/bin/env tclsh
package require Tk
proc makeTea {teas} {
puts "Entering makeTea"
set tea [lindex ${teas} [.brew curselection]]
dict with tea {
puts "brew ${Tea}, from ${Location}"
}
puts "Leaving makeTea"
}
set commands {
"Brew Tea"
"Teas In Stock"
"Teas Out Stock"
"All Teas"
"Free Containers"
"Latest Teas"
}
set teaList []
lappend teaList [dict create \
Tea Duizendblad \
LastUsed 2018-06-15 \
Location 9 \
]
lappend teaList [dict create \
Tea "Moul Ataï" \
LastUsed 2018-06-15 \
Location 12 \
]
lappend teaList [dict create \
Tea Herfst \
LastUsed 2018-06-15 \
Location A2 \
]
ttk::notebook .nb
listbox .com -height 0 -listvariable commands
.nb add .com -text Commands
listbox .brew -height [llength $teaList] -width 50 -selectmode single
bind .brew <<ListboxSelect>> [list makeTea $teaList]
foreach tea ${teaList} {
dict with tea {
.brew insert end [format {%-30s %-10s %2s} ${Tea} ${LastUsed} {$Location}]
}
}
.nb add .brew -text "Brew Tea"
pack .nb
--
Cecil Westerhof
Senior Software Engineer
LinkedIn:
http://www.linkedin.com/in/cecilwesterhof