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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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?

Regards,
Kristoffer





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:

Code:
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 www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho