scrolledListBox problem
Paul Magwene
paul.magwene at yale.edu
Wed Apr 12 17:57:54 EDT 2000
Pete wrote:
>
> I am using makeing a GUI that contains 2 scrolledListBoxes, and I have
> come across something unfortunate. When I select an item in one list,
> the currently selected item in the other list becomes deselected, so
> only one list can have an item selected at any point in time. Is this a
> bug in PMW? Any ideas as to how to fix this?
This is a Tkinter thing. By default the selection in a Listbox widget
is also the X selection, and selecting something outside the listbox
deselects it. You need to set the exportselection option to zero to get
the behavior you want.
For example,
----------------------
Pure Tkinter solution:
----------------------
from Tkinter import *
root = Tk()
sl1 = Listbox(root,exportselection=0)
sl1.insert(END,'bob')
sl1.insert(END,'fred')
sl2 = Listbox(root,exportselection=0)
sl2.insert(END,'mary')
sl2.insert(END,'jane')
sl1.pack()
sl2.pack()
root.mainloop()
-----------------------
Pmw solution
-----------------------
from Tkinter import *
import Pmw
root = Pmw.initialise()
sl1 = Pmw.ScrolledListBox(root,items=('bob','fred','mary'),
listbox_exportselection=0)
sl2 = Pmw.ScrolledListBox(root,items=('jim','john','bob'),
listbox_exportselection=0)
sl1.pack()
sl2.pack()
root.mainloop()
--
Paul Magwene
paul.magwene at yale.edu
More information about the Python-list
mailing list