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
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.
Click HERE to read and print Thinking in Tkinter. This page contains all of the programs, formatted as a single document to facilitate printing and reading. NOTE however that you really have to download and run the programs to get their full benefit.
You can download a ZIP file containing all of the programs, plus a driver file, by downloading thinking_in_tkinter.zip.
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.pyIf you are in a Windows environment, you can start thinking.bat from the command prompt simply by entering:thinkingat the command-line prompt.
You can look at the individual programs online by clicking on the following links
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.
- The Tkinter page at www.python.org Look here for many other useful links
- John Grayson's Python and Tkinter Programming. The closest thing we have to a "Tkinter bible".
- Frederik Lundh's An Introduction to Tkinter Probably the most widely-used online Tkinter documentation.
- John W. Shipman maintains a useful page on Tkinter and an especially useful Tkinter reference. Advocates use of the grid layout manager.
- Russell Owen's Tkinter Summary and TKinter Folklore
- Practical Programming in Tcl and Tk by Brent Welch - If you are going to be working with Tkinter extensively, you definitely should get a copy of this book. Highly Recommended!
- Tcl/Tk fro Programmers by J. Adrian Zimmer has an online Table of Contents page that contains links to three online chapters (11, 12, 13) on Tk. It is also available from amazon.com
- Tcl Developers Exchange
- Online Tk documentation
- Tcl and the Tk Toolkit (2nd Edition) [Paperback] is written by John Ousterhout, Tcl/Tk's original developer.
Event-Driven Programming: Introduction, Tutorial, History is my attempt to explain the basics of event-driven programming
EasyGui can help you easily put a simple GUI front-end on your Python application.
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()
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.1 EnglishThinking in Tkinter is formatted for reading and printing.
7.3 FrenchPenser en Tkinter — French translation, thanks to Gérard Labadie
7.4 ItalianTkinter per sopravvivere — Italian translation, thanks to Prof. Massimo Piai