Reputation: 169
I find this feature of automatic selection to item index 0 in the Listbox a nuisance. In my script, I have 3 listboxes called lb1,lb2 and lb3. If user selects any items on lb2 or lb3, I intend to pop up a MessageBox to ask the user to only select items from lb1. However, due to the automatic selection items index 0 in lb2 and lb3, whenever I click on item in lb1, the MessageBox also appears.
Question: How can I disable the initial selection of item index 0 in ListBox?
This is part of my script to call MessageBox if user selects items from lb2 or lb3:
if lb2.get(ACTIVE) or lb3.get(ACTIVE):
tkMessageBox.showwarning("Warning","Please select from lb1 ")
Please advice! Any other ways to perform the intended action will also do. Thanks.
Upvotes: 1
Views: 1299
Reputation: 3764
What OS are you using?
If I execute this code (taken from the Tkinter Listbox reference page on effbot.org) on Windows, there is no default selection made in the listbox.
from Tkinter import *
master=Tk()
listbox=Listbox(master)
listbox.pack()
for item in ['one','two','three','four']:
listbox.insert(END, item)
EDIT : OK, now I see what you're asking. You want to check the curselection
method first before trying to use get(ACTIVE)
.
if listbox.curselection():
item = listbox.get(ACTIVE)
Does that help? You can find a more complete example here.
Upvotes: 1