Home Contact


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


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!



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.


Widget Essentials

When to use: Use three or more (up to about five or six maximum) to allow the user to choose between several mutually exclusive options.
Tcl usage: ttk::radiobutton .ra -text "Alpha" -variable release -value 0
ttk::radiobutton .rb -text "Beta" -variable release -value 1
ttk::radiobutton .rp -text "Prod" -variable release -value 2
Ruby usage: $release = TkVariable.new ( initialValue );
Tk::Tile::RadioButton.new(parent) {text "Alpha"; 
   variable $release; value 0}
Tk::Tile::RadioButton.new(parent) {text "Beta"; 
   variable $release; value 1}
Tk::Tile::RadioButton.new(parent) {text "Prod"; 
   variable $release; value 2}
Reference: (at www.tcl.tk)

Common Options

text The text label to be shown next to the radiobutton itself.
variable A variable linked to the radiobutton; when the variable is changed, the radiobutton will reflect the new value, while if the user selects the radiobutton, the variable's value will be updated. If the variable has not been initialized, the radiobutton is shown in an indeterminate state, which usually implies that a choice has not yet been made (and that a default choice is inappropriate).
value Value to use when that radiobutton is selected. If the linked variable contains this value, the radiobutton is selected (filled in), otherwise it is unselected (empty).

How do I...

See which radiobutton is selected? Look at the linked variable.
Change which radiobutton is selected? Change the linked variable to the value of the radiobutton you'd like to select.
See if it's in the indeterminate state? Check if the variable has not been initialized.
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 radiobutton is pressed.
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.