467,877 Members | 1,008 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

tkinter listboxes

I will give a simplified example of the problem at hand --

I have a case in which I have two listboxes - listbox1 and listbox2,
if I click on an item in listbox1 the item gets highlighted as
expected. Now if I click on an item in listbox2 the selected item in
listbox1 loses its highlight. My question is how do I keep the
listbox1 item from losing its highlight if I select an item in
listbox2 or to that matter any other widget.

Thanks
Rahul

May 4 '07 #1
  • viewed: 2125
Share:
3 Replies
ra********@yahoo.com wrote:
I will give a simplified example of the problem at hand --

I have a case in which I have two listboxes - listbox1 and listbox2,
if I click on an item in listbox1 the item gets highlighted as
expected. Now if I click on an item in listbox2 the selected item in
listbox1 loses its highlight. My question is how do I keep the
listbox1 item from losing its highlight if I select an item in
listbox2 or to that matter any other widget.

Thanks
Rahul
You will need to bind '<Button-1>' for each list box to something like:
def button1(e):
row = e.widget.lists[0].nearest(e.y)
e.widget.selection_clear(0, END)
e.widget.selection_set(row)
return 'break'

# how to bind
alistbox.bind('<Button-1>', button1)
The less than obvious thing here is that selections (highlighted here)
are different than the active index (which is marked with an underline).
You are probably using the active index and don't realize the difference.

James
May 4 '07 #2
On Fri, 04 May 2007 05:26:56 +0200, <ra********@yahoo.comwrote:
I will give a simplified example of the problem at hand --

I have a case in which I have two listboxes - listbox1 and listbox2,
if I click on an item in listbox1 the item gets highlighted as
expected. Now if I click on an item in listbox2 the selected item in
listbox1 loses its highlight. My question is how do I keep the
listbox1 item from losing its highlight if I select an item in
listbox2 or to that matter any other widget.
By default, the 'highlighting' is considered as a selection. Since you
can't have two items selected at the same time, the second cancels the
first. To avoid this behaviour, make each list keep its selection to
itself by using the 'exportselection=0' option when you create the Listbox
instance. This should work as you expect.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
May 4 '07 #3
On May 4, 1:55 am, "Eric Brunel" <eric.bru...@pragmadev.comwrote:
On Fri, 04 May 2007 05:26:56 +0200, <rahulna...@yahoo.comwrote:
I will give a simplified example of the problem at hand --
I have a case in which I have two listboxes - listbox1 and listbox2,
if I click on an item in listbox1 the item gets highlighted as
expected. Now if I click on an item in listbox2 the selected item in
listbox1 loses its highlight. My question is how do I keep the
listbox1 item from losing its highlight if I select an item in
listbox2 or to that matter any other widget.

By default, the 'highlighting' is considered as a selection. Since you
can't have two items selected at the same time, the second cancels the
first. To avoid this behaviour, make each list keep its selection to
itself by using the 'exportselection=0' option when you create the Listbox
instance. This should work as you expect.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

Eric that works. Thank You. James thank you for the detailed
explanation it will be useful for me.
Regards
Rahul

May 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jeffrey Barish | last post: by
2 posts views Thread by Zhang Le | last post: by
1 post views Thread by custard_pie | last post: by
reply views Thread by syed_saqib_ali | last post: by
4 posts views Thread by bill yeager | last post: by
reply views Thread by Terry D | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
1 post views Thread by Michael Yanowitz | last post: by
3 posts views Thread by rahulnag22 | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.