Modern Tkinter

Modern Tkinter ebook

Want TkDocs to go? If you've found the material on this site useful, please consider buying this book, which is based on the Python material in the tutorial.

Mark Roseman

p.s. your purchase helps me improve this site... thank you!


Only $10 for e-book. pick your format:

Paperback PDF Kindle Apple Books B&N Nook Kobo

(Slightly more for paperback. Also available on other e-book platforms.)

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: When you want your user to invoke some operation (submit a dialog, calculate a result, save a file, etc.)
Tcl:ttk::button .b -text "Okay" -command "submitForm"
Ruby:b = {text "Okay"; command "submitForm"}
Perl:my $b = parent->new_ttk__button(-text => "Okay", -command => sub {submitForm();});
Python:b = ttk.Button(parent, text="Okay", command=submitForm)

Common Options

text The label to be shown in the button.
command The script to invoke when the button is pressed.
default If "active", this is a "default" button for the window, i.e. the one that will be invoked if the user presses Return. Regular state is "normal" (You need to set up the event binding separately.)
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.

How do I...

Press the button from my program? Use the "invoke" method. Useful so you don't need to repeat the button's command script in multiple places in your program.
Disable the button? Use the "state disabled" method.
You can reenable this with "state !disabled".
Check with "instate disabled" (returns 1 if disabled, else 0).