Skip to Main Content
Programming Python, 3rd Edition
book

Programming Python, 3rd Edition

by Mark Lutz
August 2006
Intermediate to advanced content levelIntermediate to advanced
1600 pages
51h 46m
English
O'Reilly Media, Inc.
Content preview from Programming Python, 3rd Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python, 3rd Edition

Learning Python, 3rd Edition

Mark Lutz

Publisher Resources

ISBN: 0596009259Supplemental ContentErrata Page