Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with ttk:notebook

32 views
Skip to first unread message

Cecil Westerhof

unread,
Jun 27, 2018, 4:59:07 AM6/27/18
to
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

Brad Lanam

unread,
Jun 27, 2018, 7:39:25 AM6/27/18
to
Yeah, none of the selections in the first tab should do anything.
What's happening is the .brew bind is firing for the .com listbox and
[.brew curselection] is empty and the code fails.

a) The binds look fine for both .com and .brew.
b) No idea why .brew is losing its curselection.

I don't use listboxes much, but e.g. the ones in
the 'fontchooser' code work fine.

I have confirmed that the same bind script is firing for .com.

Still researching.

Brad Lanam

unread,
Jun 27, 2018, 8:09:29 AM6/27/18
to
Add "-exportselection 0" to your listbox's.

a) That's a really bad default for listbox.
b) There's obviously a bug involved with -exportselection.


Brad Lanam

unread,
Jun 27, 2018, 8:13:50 AM6/27/18
to
Well, (b) may be wrong based on the manual page.
I don't know all the details on how
-exportselection is supposed to work. But I will still go with (a).

Cecil Westerhof

unread,
Jun 27, 2018, 9:44:05 AM6/27/18
to
Solves the problem: thanks.
0 new messages