Home Contact

TkDocs

Information you need to build high-quality Tk user interfaces.

close

Modern Tkinter ebook If you've found the material on this site useful, please consider purchasing this e-book (only $10), which is based on the Python material in the tutorial. Doing so helps me maintain and update this site. Thank you very much!


 
 
@markroseman
mark@markroseman.com

 

Kindle Buy now for your Kindle
Kindle apps are also available for most smartphones, tablets, and desktops. Payment and download handled by Amazon's Kindle Store.

 

PDF Buy the DRM-free PDF
Downloads handled by SendOwl.com. Payment handled via PayPal
(click "Don't have a PayPal account" to use a credit card).

The widget roundup provides you with a quick and easy reference to the most important features and options for each Tk widget.

Checkbutton

Widget Essentials

When to use: To allow the user to choose between two mutually exclusive choices.
Tcl usage: ttk::checkbutton .cb -text "Self-destruct on close" 
   -variable destructFlag
Ruby usage: $destructFlag = TkVariable.new ( initialValue );
Tk::Tile::Checkutton.new(parent) { 
   text "Self-destruct on close"; variable $destructFlag}
Reference: (at www.tcl.tk)

Common Options

text The text label to be shown next to the checkbox.
variable A variable linked to the checkbutton; when the variable is changed, the checkbutton will reflect the new value, while if the user toggles the checkbutton, the variable's value will be updated.
onvalue,
offvalue
Values reflecting the checked (default 1) and unchecked (default 0), which are held in the linked variable. If the variable contains neither of these values, the checkbutton is put into an indeterminate state, which usually implies that the choice has not yet been made (and that a default choice is inappropriate).

How do I...

See if the checkbutton is checked? Look at the linked variable.
Check or uncheck it? Change the linked variable to either the onvalue or offvalue.
See if it's in the indeterminate state? Check if the variable holds a value other than the onvalue and offvalue.
You can also use the "instate alternate" method.
Disable the checkbutton? Use the "state disabled" method.
You can reenable this with "state !disabled".
Check with "instate disabled" (returns 1 if disabled, else 0).

Less Common Options

textvariable As an alternative to text, get the string from a variable, updating when the variable changes.
command The script to invoke when the checkbutton is pressed.
image,
compound
Specify a Tk Image object (not the path to an image file) instead of the text label. If compound is center, top, bottom, left, or right, display the text and the image.