Checkbutton, Radiobutton, and Scale
This section introduces three widget types: the Checkbutton (a multiple-choice input
widget), the Radiobutton (a
single-choice device), and the Scale (sometimes known as a “slider”). All
are variations on a theme and are somewhat related to simple buttons,
so we’ll explore them as a group here. To make these widgets more fun
to play with, we’ll reuse the dialogTable module shown in Example 9-8 to provide callbacks
for widget selections (callbacks pop up dialog boxes). Along the way,
we’ll also use the Tkinter variables we just met to communicate with
these widgets’ state settings.
Checkbuttons
The Checkbutton and
Radiobutton widgets are designed
to be associated with Tkinter variables: clicking the button changes
the value of the variable, and setting the variable changes the
state of the button to which it is linked. In fact, Tkinter
variables are central to the operation of these widgets:
A collection of
Checkbuttons implements a multiple-choice interface by assigning each button a variable of its own.A collection of
Radiobuttons imposes a mutually exclusive single-choice model by giving each button a unique value and the same Tkinter variable.
Both kinds of buttons provide both command and variable options. The command option lets you register a
callback to be run immediately on button-press events, much like
normal Button widgets. But by
associating a Tkinter variable with the variable option, you can also fetch or change widget state at ...