So I just came across this issue, and it's been driving me crazy for a couple hours now...
I have a Listbox with several items on it. I bind the <<ListboxSelect>> event binded to a function called onSelected.
This function should print the item that got selected but here's the issue. It prints the last active item rather than the new one.
Here's is an example: I have 2 items, Item1 and Item2, I select them in the following order:
Item1-Item2-Item1-Item2-Item1
and this is output:
Item1-Item1-Item2-Item1-Item2
Clearly the first one works, but from there it's like the event is thrown before the 'active' item is updated and prints the last 'active' item. Obviously, if i click twice the same item it works as intended.
Is there a workaround for this? I tried waiting for the Listbox to update with update_idletasks(), but didn't solve the problem.
What can i do here?
Thanks in advance!
EDIT:
Someone asked for code...:
self.phase = tk.Listbox(self, exportselection = False, selectmode='single')
self.phase.bind('<<ListboxSelect>>', self.onselect)
def onselect(self, evt):
print(self.phase.get('active'))
print(self.phase.select_includes(self.phase.index('active')))
Note that the second print is always False besides the first one.
<<ListboxSelect>>events won't fire until after the selection has changed; callingcurselectionfrom a handler bound to that event should always get the currently selected items. - Bryan Oakleycurselectionrather thanget('active')... - Marc Samarra Deumal