6.4. Radio Buttons

Radio buttons are similar to check buttons except they are grouped
so that only one may be selected/depressed at a time. This is good for
places in your application where you need to select from a short list of
options.

Creating a new radio button is done with this call:

radio_button = gtk.RadioButton(group=None, label=None)

You'll notice the extra argument to this call. Radio buttons
require a group to operate properly. The first call
to gtk.RadioButton() should pass
None as the first argument and a new radio button group
will be created with the new radio button as its only member.

To add more radio buttons to a group, pass in a reference to a
radio button in group in subsequent calls to
gtk.RadioButton().

If a label argument is specified the text
will be parsed for '_'-prefixed mnemonic characters.

It is also a good idea to explicitly set which button should be
the default depressed button with:

radio_button.set_active(is_active)

This is described in the section on toggle buttons, and works in
exactly the same way. Once the radio buttons are grouped together, only one
of the group may be active at a time. If the user clicks on one radio
button, and then on another, the first radio button will first emit a
"toggled" signal (to report becoming inactive), and then the second will
emit its "toggled" signal (to report becoming active).

The code is fairly straight forward. Lines 63-64 make the
"close" button the default widget so that pressing the "Enter" key when the
window is active causes the "close" button to emit the "clicked"
signal.