5 # Demonstrate multiple groups of radio buttons
9 from WindowParent
import WindowParent
, MainLoop
10 from HVSplit
import HSplit
, VSplit
14 # Create the widget hierarchy, top-down
16 # 1. Create the window
18 window
= WindowParent().create('Radio Groups', (0, 0))
20 # 2. Create a horizontal split to contain the groups
22 topsplit
= HSplit().create(window
)
24 # 3. Create vertical splits, one for each group
26 group1
= VSplit().create(topsplit
)
27 group2
= VSplit().create(topsplit
)
28 group3
= VSplit().create(topsplit
)
30 # 4. Create individual radio buttons, each in their own split
32 b11
= RadioButton().definetext(group1
, 'Group 1 button 1')
33 b12
= RadioButton().definetext(group1
, 'Group 1 button 2')
34 b13
= RadioButton().definetext(group1
, 'Group 1 button 3')
36 b21
= RadioButton().definetext(group2
, 'Group 2 button 1')
37 b22
= RadioButton().definetext(group2
, 'Group 2 button 2')
38 b23
= RadioButton().definetext(group2
, 'Group 2 button 3')
40 b31
= RadioButton().definetext(group3
, 'Group 3 button 1')
41 b32
= RadioButton().definetext(group3
, 'Group 3 button 2')
42 b33
= RadioButton().definetext(group3
, 'Group 3 button 3')
44 # 5. Define the grouping for the radio buttons.
45 # Note: this doesn't have to be the same as the
46 # grouping is splits (although it usually is).
47 # Also set the 'hook' procedure for each button
49 list1
= [b11
, b12
, b13
]
50 list2
= [b21
, b22
, b23
]
51 list3
= [b31
, b32
, b33
]
63 # 6. Select a default button in each group
69 # 6. Realize the window
73 # 7. Dispatch events until the window is closed
77 # 8. Report final selections
79 print 'You selected the following choices:'
80 if b11
.selected
: print '1.1'
81 if b12
.selected
: print '1.2'
82 if b13
.selected
: print '1.3'
83 if b21
.selected
: print '2.1'
84 if b22
.selected
: print '2.2'
85 if b23
.selected
: print '2.3'
86 if b31
.selected
: print '3.1'
87 if b32
.selected
: print '3.2'
88 if b33
.selected
: print '3.3'
92 # This is placed as 'hook' attribute on each button.
93 # The example just prints the title of the selected button.
96 print 'Selected:', self
.text