Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | title = 'Pmw.RadioSelect 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 and pack a horizontal RadioSelect widget. | |
13 | horiz = Pmw.RadioSelect(parent, | |
14 | labelpos = 'w', | |
15 | command = self.callback, | |
16 | label_text = 'Horizontal', | |
17 | frame_borderwidth = 2, | |
18 | frame_relief = 'ridge' | |
19 | ) | |
20 | horiz.pack(fill = 'x', padx = 10, pady = 10) | |
21 | ||
22 | # Add some buttons to the horizontal RadioSelect. | |
23 | for text in ('Fruit', 'Vegetables', 'Cereals', 'Legumes'): | |
24 | horiz.add(text) | |
25 | horiz.invoke('Cereals') | |
26 | ||
27 | # Create and pack a multiple selection RadioSelect widget. | |
28 | self.multiple = Pmw.RadioSelect(parent, | |
29 | labelpos = 'w', | |
30 | command = self.multcallback, | |
31 | label_text = 'Multiple\nselection', | |
32 | frame_borderwidth = 2, | |
33 | frame_relief = 'ridge', | |
34 | selectmode = 'multiple', | |
35 | ) | |
36 | self.multiple.pack(fill = 'x', padx = 10) | |
37 | ||
38 | # Add some buttons to the multiple selection RadioSelect. | |
39 | for text in ('Apricots', 'Eggplant', 'Rice', 'Lentils'): | |
40 | self.multiple.add(text) | |
41 | self.multiple.invoke('Rice') | |
42 | ||
43 | # Create and pack a vertical RadioSelect widget, with checkbuttons. | |
44 | self.checkbuttons = Pmw.RadioSelect(parent, | |
45 | buttontype = 'checkbutton', | |
46 | orient = 'vertical', | |
47 | labelpos = 'w', | |
48 | command = self.checkbuttoncallback, | |
49 | label_text = 'Vertical,\nusing\ncheckbuttons', | |
50 | hull_borderwidth = 2, | |
51 | hull_relief = 'ridge', | |
52 | ) | |
53 | self.checkbuttons.pack(side = 'left', expand = 1, padx = 10, pady = 10) | |
54 | ||
55 | # Add some buttons to the checkbutton RadioSelect. | |
56 | for text in ('Male', 'Female'): | |
57 | self.checkbuttons.add(text) | |
58 | self.checkbuttons.invoke('Male') | |
59 | self.checkbuttons.invoke('Female') | |
60 | ||
61 | # Create and pack a RadioSelect widget, with radiobuttons. | |
62 | radiobuttons = Pmw.RadioSelect(parent, | |
63 | buttontype = 'radiobutton', | |
64 | orient = 'vertical', | |
65 | labelpos = 'w', | |
66 | command = self.callback, | |
67 | label_text = 'Vertical,\nusing\nradiobuttons', | |
68 | hull_borderwidth = 2, | |
69 | hull_relief = 'ridge', | |
70 | ) | |
71 | radiobuttons.pack(side = 'left', expand = 1, padx = 10, pady = 10) | |
72 | ||
73 | # Add some buttons to the radiobutton RadioSelect. | |
74 | for text in ('Male', 'Female', 'Both', 'Neither'): | |
75 | radiobuttons.add(text) | |
76 | radiobuttons.invoke('Both') | |
77 | ||
78 | def callback(self, tag): | |
79 | # This is called whenever the user clicks on a button | |
80 | # in a single select RadioSelect widget. | |
81 | print 'Button', tag, 'was pressed.' | |
82 | ||
83 | def multcallback(self, tag, state): | |
84 | # This is called whenever the user clicks on a button | |
85 | # in the multiple select RadioSelect widget. | |
86 | if state: | |
87 | action = 'pressed.' | |
88 | else: | |
89 | action = 'released.' | |
90 | ||
91 | print 'Button', tag, 'was', action, \ | |
92 | 'Selection:', self.multiple.getcurselection() | |
93 | ||
94 | def checkbuttoncallback(self, tag, state): | |
95 | # This is called whenever the user clicks on a button | |
96 | # in the checkbutton RadioSelect widget. | |
97 | if state: | |
98 | action = 'pressed.' | |
99 | else: | |
100 | action = 'released.' | |
101 | ||
102 | print 'Button', tag, 'was', action, \ | |
103 | 'Selection:', self.checkbuttons.getcurselection() | |
104 | ||
105 | ###################################################################### | |
106 | ||
107 | # Create demo in root window for testing. | |
108 | if __name__ == '__main__': | |
109 | root = Tkinter.Tk() | |
110 | Pmw.initialise(root) | |
111 | root.title(title) | |
112 | ||
113 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) | |
114 | exitButton.pack(side = 'bottom') | |
115 | widget = Demo(root) | |
116 | root.mainloop() |