Figure 8-28 shows what this script generates when run. Pressing any of this window’s
radio buttons triggers its command handler, pops up one of the standard dialog boxes we
met earlier, and automatically deselects the button previously pressed. Like check but-
tons, radio buttons are packed; this script packs them to the top to arrange them ver-
tically, and then anchors each on the northwest corner of its allocated space so that
they align well.
Figure 8-28. demoRadio in action
Like the check button demo script, this one also puts up a State button to run the class’s
report method and to show the current radio state (the button selected). Unlike the
check button demo, this script also prints the return values of dialog demo calls that
are run as its buttons are pressed. Here is what the stdout stream looks like after a few
presses and state dumps; states are shown in bold:
C:\...\PP4E\Gui\Tour> python demoRadio.py
you pressed Input
result: 3.14
Input
you pressed Open
result: C:/PP4thEd/Examples/PP4E/Gui/Tour/demoRadio.py
Open
you pressed Query
result: yes
Query
Radio buttons and variables
So, why variables here? For one thing, radio buttons also have no “get” widget method
to fetch the selection in the future. More importantly, in radio button groups, the
value and variable settings turn out to be the whole basis of single-choice behavior. In
Checkbutton, Radiobutton, and Scale | 463