Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
listbox question

Posted by toffe (toffe), 10 May 2005
I'm a tcl/tk newbie with a listbox problem.

I have a listbox with a number of entries. I also have an entry widget which is supposed to assign a position in a list depending on what is selected in the listbox.

I do curselection on ButtonPress and ButtonRealease in the listbox to find out which index was selected and which is now selected. This in order to save away the entry to the approriate position in my list and then update the entry with the value from the new selection.

Problem is that when I use tab to go to the entry or when I select the text in the entry the highlight in the listbox disappears and curselection return an empty string.  If I just click the entry and enter a value it all works fine.

How can I gets this working the way I want?


Posted by admin (Graham Ellis), 10 May 2005
Can you supply some sample code?  I tried to work out the sequences that you've described and came up with:

set tabbing 0

proc report {} {
       set words [.what get]
       set times [.time curselection]
       .say config -text "$words @ $times"

listbox .time -height 0
.time insert end morning
.time insert end afternoon
.time insert end evening

entry .what -width 20

button .done -text report -command report

label .say -text ----
button .quit -text quit -command exit

pack .time .what .done .say .quit -expand y -fill both

bind .time <Key-Tab>  {
       global times
       global tabbing
       set times [.time curselection]
       .say config -text "TABBING off $times"
       set tabbing 1

bind .what <Enter>  {
       global times
       global tabbing
       if {$tabbing} {
               .time selection set $times
       set tabbing 0

I think the bind commands at the very end might be your solution - the first notices when you tab off the listbox and telly you which item was selected at the time ... the second resets that on the listbox when you enter text in the entry box.

The report button and label don't relate directly to the question - they just help you see the state of the variables and how the test code works if you try it out.

Posted by toffe (toffe), 12 May 2005
Thanks for your detailed answer!

That would certainly solve the tabbing issue. If you select an item in your listbox and then select the text in the entry you have my other problem  though. I.e you select the text in the entry so that it is highlighted as you would if you wanted to replace it. Is the solution to bind the Leave event so that whenever the mouse leaves the listbox i save what the selection was?

I'm going to try this out a bit. Wish there was some practical way to always leave the selected item in the listbox highlighted and selected.

Thanks again!

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho