Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | title = 'Pmw.ComboBox 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 | parent.configure(background = 'white') | |
13 | ||
14 | # Create and pack the widget to be configured. | |
15 | self.target = Tkinter.Label(parent, | |
16 | relief = 'sunken', | |
17 | padx = 20, | |
18 | pady = 20, | |
19 | ) | |
20 | self.target.pack(fill = 'x', padx = 8, pady = 8) | |
21 | ||
22 | # Create and pack the simple ComboBox. | |
23 | words = ('Monti', 'Python', 'ik', 'den', 'Holie', 'Grailen', '(Bok)') | |
24 | simple = Pmw.ComboBox(parent, | |
25 | label_text = 'Simple ComboBox:', | |
26 | labelpos = 'nw', | |
27 | selectioncommand = self.changeText, | |
28 | scrolledlist_items = words, | |
29 | dropdown = 0, | |
30 | ) | |
31 | simple.pack(side = 'left', fill = 'both', | |
32 | expand = 1, padx = 8, pady = 8) | |
33 | ||
34 | # Display the first text. | |
35 | first = words[0] | |
36 | simple.selectitem(first) | |
37 | self.changeText(first) | |
38 | ||
39 | # Create and pack the dropdown ComboBox. | |
40 | colours = ('cornsilk1', 'snow1', 'seashell1', 'antiquewhite1', | |
41 | 'bisque1', 'peachpuff1', 'navajowhite1', 'lemonchiffon1', | |
42 | 'ivory1', 'honeydew1', 'lavenderblush1', 'mistyrose1') | |
43 | dropdown = Pmw.ComboBox(parent, | |
44 | label_text = 'Dropdown ComboBox:', | |
45 | labelpos = 'nw', | |
46 | selectioncommand = self.changeColour, | |
47 | scrolledlist_items = colours, | |
48 | ) | |
49 | dropdown.pack(side = 'left', anchor = 'n', | |
50 | fill = 'x', expand = 1, padx = 8, pady = 8) | |
51 | ||
52 | # Display the first colour. | |
53 | first = colours[0] | |
54 | dropdown.selectitem(first) | |
55 | self.changeColour(first) | |
56 | ||
57 | def changeColour(self, colour): | |
58 | print 'Colour: ' + colour | |
59 | self.target.configure(background = colour) | |
60 | ||
61 | def changeText(self, text): | |
62 | print 'Text: ' + text | |
63 | self.target.configure(text = text) | |
64 | ||
65 | ###################################################################### | |
66 | ||
67 | # Create demo in root window for testing. | |
68 | if __name__ == '__main__': | |
69 | root = Tkinter.Tk() | |
70 | Pmw.initialise(root) | |
71 | root.title(title) | |
72 | ||
73 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) | |
74 | exitButton.pack(side = 'bottom') | |
75 | widget = Demo(root) | |
76 | root.mainloop() |