Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | title = 'Pmw.SelectionDialog demonstration' |
2 | ||
3 | # Import Pmw from this directory tree. | |
4 | import sys | |
5 | sys.path[:0] = ['../../..'] | |
6 | ||
7 | import Tkinter | |
8 | import Pmw | |
9 | ||
10 | class Demo: | |
11 | def __init__(self, parent): | |
12 | # Create the dialog. | |
13 | self.dialog = Pmw.SelectionDialog(parent, | |
14 | title = 'My SelectionDialog', | |
15 | buttons = ('OK', 'Cancel'), | |
16 | defaultbutton = 'OK', | |
17 | scrolledlist_labelpos = 'n', | |
18 | label_text = 'What do you think of Pmw?', | |
19 | scrolledlist_items = ('Cool man', 'Cool', 'Good', 'Bad', 'Gross'), | |
20 | command = self.execute) | |
21 | self.dialog.withdraw() | |
22 | ||
23 | # Create button to launch the dialog. | |
24 | w = Tkinter.Button(parent, text = 'Show selection dialog', | |
25 | command = self.dialog.activate) | |
26 | w.pack(padx = 8, pady = 8) | |
27 | ||
28 | def execute(self, result): | |
29 | sels = self.dialog.getcurselection() | |
30 | if len(sels) == 0: | |
31 | print 'You clicked on', result, '(no selection)' | |
32 | else: | |
33 | print 'You clicked on', result, sels[0] | |
34 | self.dialog.deactivate(result) | |
35 | ||
36 | ###################################################################### | |
37 | ||
38 | # Create demo in root window for testing. | |
39 | if __name__ == '__main__': | |
40 | root = Tkinter.Tk() | |
41 | Pmw.initialise(root) | |
42 | root.title(title) | |
43 | ||
44 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) | |
45 | exitButton.pack(side = 'bottom') | |
46 | widget = Demo(root) | |
47 | root.mainloop() |