Thinking in Tkinter

Text updated: 2009-12-26
References & links updated: 2011-10-26
This project is no longer active.
Contact the author:
Stephen Ferg

Table of Contents

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

1 About Thinking in Tkinter

I've been trying to teach myself Tkinter out of various books, and I'm finding it more difficult than I think it should be.

The problem is that the authors of the books want to rush into telling me about all of the widgets in the Tkinter toolbox, but never really pause to explain basic concepts. They don't explain how to "think in Tkinter". So I thought that I would try to write the kind of book that I wanted to read. Or at least the sketch of such a book.

Thinking in Tkinter consists of a few short programs that begin to explain how to think in Tkinter. In them, I don't attempt to catalog all of the types of widgets, attributes, and methods that are available in Tkinter. I just try to get started down the road of understanding some basic Tkinter concepts.

These programs do not attempt to provide a comprehensive introduction to all aspects of Tkinter programming. For that, I refer you to Frederik Lundh's An Introduction to Tkinter, John Shipman's Tkinter reference, and the other useful references at the bottom of this page.

Above all, I must emphasize that Practical Programming in Tcl and Tk by Brent Welch is absolutely essential for working with Tk and Tkinter. Get this book!

Note that you should not run these programs under IDLE.   IDLE is itself a Tkinter application, with its own "mainloop" that will conflict with the mainloop in these programs. If you really want to view and run these programs using IDLE, then -- for each program -- you should comment out the "mainloop" statement in the program before running it.

This material has been substantially improved by feedback from folks on comp.lang.python. A big "Thank you!" to Alan Colburn, Jeff Epler, Greg Ewing, Tom Good, Steve Holden, Joseph Knapka, Gerrit Muller, Russell Owen, and Chad Netzer. Thanks to Terry Carroll for catching and reporting typos.

— Stephen Ferg

2 Thinking in Tkinter — formatted for reading and printing

Thinking in Tkinter consists of a set of Python programs. Each program contains a long documentation string with text that explains certain concepts, followed by executable code that illustrates the concepts.

You can download an HTML file containing all of the programs, formatted as a single document to facilitate printing and reading, (ThinkingInTkinter.html) from the project files page. NOTE however that you really have to download and run the programs to get their full benefit.


3 Thinking in Tkinter — downloadable zip file

You can download a ZIP file containing all of the programs, plus a driver file (thinking_in_tkinter.zip) from the project files page.

This zip file contains the Thinking in Tkinter Python files, plus a driver program called thinking.py and a batch file called thinking.bat. To install these files, simply unzip the zip file into a directory (i.e. folder) of your choice. Once the have been unzipped, make that directory your current directory. You can then start the programs from the command prompt by entering:

python thinking.py
If you are in a Windows environment, you can start thinking.bat from the command prompt simply by entering:
thinking
at the command-line prompt.

4 Thinking in Tkinter — as individual programs online

You can look at the individual programs online by clicking on the following links


5 Tcl, Tk, and Tkinter Resources

Most Tkinter documentation is fairly old, but since Tkinter "hasn't evolved much has been stable for a long time, even old Tkinter documentation is still useful.

5.1 Tkinter

5.2 Tcl and Tk


5.3 Quasi-related stuff by Steve Ferg

5.4 A Tip for Beginniners

This is a problem that puzzles many beginning Tkinter programmers. Fredrik Lundh has the answer.

Question:
I am just starting with Python.
When I use Tk, a blank dialog always opens up behind tkMessageBox or whatever other GUI element that one executes.
Is their a way of disabling this?

Answer:

The "blank dialog" is Tkinter's root window.
To eliminate that, explicitly create a root and withdraw it before proceeding:

       root = Tkinter.Tk()
       root.withdraw()

6 License Information


This work is licensed under the Creative Commons Attribution 3.0 License. You are free to copy, distribute, and display the work, and to make derivative works (including translations). If you do, you must give the original author credit. The author specifically permits and encourages teachers to post, reproduce, distribute and translate all or part of this material for use in their classes or by their students. It is not necessary to ask permission.

7 Downloads

7.1 English

Flag of USA Flag of United Kingdom Thinking in Tkinter is formatted for reading and printing.

7.2 Brazilian

Flag of Brazil Pensando em Tkinter (pdf) — Brazilian/Portugese translation, thanks to J. Labaki, a Ph.D. student at the Department of Computational Mechanics, State University of Campinas, Brazil

7.3 French

Flag of France Penser en Tkinter — French translation, thanks to Gérard Labadie

7.4 Italian

Flag of Italy Tkinter per sopravvivere — Italian translation, thanks to Prof. Massimo Piai

END OF PAGE