Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter Listbox loses its selection when clicking elsewhere on the form

When a tkinter form includes a listbox and other widgets, clicking on the other widgets (especially if the mouse is dragged) causes the listbox to lose its selection -- meaning that the element(s) that was/were selected/highlighted in the lisbox become unselected.

I've seen this problem discussed in one or two places on the Net, with this solution proposed: set the listbox exportselection value to False:

lb = Listbox(leftPane, width=24, height=4, selectmode=EXTENDED)
lb.exportselection = False

But that doesn't work at all in my apps. (Tried on Tkinter 8.5 and Tkinter 8.6.1, Python 3.3, Python 3.4... on a variety of Linux distributions. The problem is remarkably constant, regardless of the app in which the listobox is, or the environment in which it's deployed.)

Ideas?

like image 328
Karpov Avatar asked Sep 20 '25 10:09

Karpov


1 Answers

You are doing it wrong. You need to use the config (or configure) method:

lb.configure(exportselection=False)
like image 103
Bryan Oakley Avatar answered Sep 22 '25 23:09

Bryan Oakley