Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with two listboxes

Status
Not open for further replies.

oragonefreet

Programmer
Jul 28, 2008
6
FR
Hello,

My Tk window uses two independant listboxes named as :

.saving.right.tables.tablist.lbox
.saving.right.sequences.seqlist.lbox

I'd like the user could select entries in the first and in the second listbox. Meanwhile when i select something in one, it clears entire selection in the other listbox.

Example, i use :
.saving.right.tables.tablist.lbox selection set 0 end

and all selection in .saving.right.sequences.seqlist.lbox has been cleared.

Is there a mean to prevent this ?

Thanks,
Oragon.
 
Listboxes only keep their selection when they have focus. Let's see your code and we can work around this.

In the mean time, consider this. Let's make two lists:
set lstA {a b c d e f}
set lstB {u v w x y z}


Now I'll set up two frames, side by side, each containing one listbox, each pointing to one of the lists:
pack [frame .f1 -borederwidth 4] -side left
pack [frame .f2 -borderwidth 4] -side left
pack [listbox .f1.lb1 -listvariable lstA -selectmode multiple] -side top
pack [listbox .f2.lb2 -listvariable lstB -selectmode multiple] -side top


Now we can create buttons to capture the selections:
pack [button .f1.bt1 -text Select] -side top
pack [button .f2.bt2 -text Select] -side top
.f1.bt1 configure -command {set lstS1 [.f1.bt1 curselection]}
.f2.bt2 configure -command {set lstS2 [.f2.bt2 curselection]}


_________________
Bob Rashkin
 
That's certainly the easiest way. You can do it with bindings but it's both complicated and error-prone, especially with multiple selections.

_________________
Bob Rashkin
 
I've found solution.
In fact, i merged the two listbox in one, and added a button. Clicking the button make the listbox change displaying.

The button saves the selections, as you said, before changing it's content in order to restore it when we will re-click on the it to show the first content.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top