1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
""" Demonstration of the Pmw ScrolledListBox megawidget.
"""
# Import Pmw from the sibling directory.
import sys
sys.path[:0] = ['../../..']
import Tkinter
import Pmw
class Demo:
def __init__(self, parent):
# Create and pack the ScrolledListBox.
self.box = Pmw.ScrolledListBox(parent,
listbox_selectmode='single',
items=('Sydney', 'Melbourne', 'Brisbane'),
label_text='Cities',
labelpos='nw',
vscrollmode = 'static',
selectioncommand=self.selectionCommand,
dblclickcommand=self.defCmd)
self.box.pack(fill = 'both', expand = 'yes', padx = 10, pady = 10)
items = ('AndaMooka', 'Coober Pedy', 'Innamincka', 'Oodnadatta')
self.box.setlist(items)
self.box.insert(2, 'Wagga Wagga', 'Perth')
self.box.insert('end', 'Darwin')
index = list(self.box.get(0, 'end')).index('Wagga Wagga')
self.box.delete(index)
self.box.delete(6, 7)
self.box.insert('end', 'Bulli', 'Alice Springs')
apply(self.box.insert, ('end',) + tuple(range(10)))
def selectionCommand(self):
sels = self.box.getcurselection()
if len(sels) == 0:
print 'No selection'
else:
print 'Selection:', sels[0]
def defCmd(self):
sels = self.box.getcurselection()
if len(sels) == 0:
print 'No selection for double click'
else:
print 'Double click:', sels[0]
######################################################################
# Create demo in root window for testing.
if __name__ == '__main__':
root = Tkinter.Tk()
Pmw.initialise(root, fontScheme = 'pmw1')
root.title('Pmw ScrolledListBox demonstration')
exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
exitButton.pack(side = 'bottom')
widget = Demo(root)
root.mainloop()
|