473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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
3 2284
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
2
by: Zhang Le | last post by:
Hello, Is there a quick way to replace the content of a single item in tkinter's listbox? Currently my solution is to first delete the item, then insert a new item at the same position. I think...
1
by: custard_pie | last post by:
Hi,..I found it difficult to display data from a dictionary using GUI. What widget should I use? I tried using text widget, but I couldn't get the display I want. I need the display to look like...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: rahulnag22 | last post by:
Hi, I have developed a GUI using tkinter (grid geometory manager). The structure is a top frame containing multiple subframes. Each subframe has a combination of widgets like(Entry, label,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.