|
Thinking in TkinterHomeUpdated: 2006-01-21 Contact Stephen Ferg |
|
This work is licensed under the
Creative
Commons Attribution 2.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.
Thinking in Tkinter is formatted for reading and printing. For more information, see below.
thinking_in_tkinter.zip contains the Thinking in Tkinter Python files. For more information, see below.
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.
Pensando em Tkinter — Brazilian/Portugese
Tkinter per sopravvivere — Italian
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, Tkinter: GUI Programming with Python at the New Mexico Tech Computer Center, 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.
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.
Thinking in Tkinter — Formatted for reading and printing
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.
All programs in a ZIP file
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.
Individual programs online
You can look at the individual programs online by clicking on the following links
- thinking_py.txt - the driver program
- tt000_py.txt - introduction
- tt010_py.txt - simplest possible Tkinter program: 3 statements
- tt020_py.txt - creating a GUI object; packing; containers vs. widgets
- tt030_py.txt - creating a widget and putting it in a frame
- tt035_py.txt - using a class structure in the program
- tt040_py.txt - some other ways to define a widget
- tt050_py.txt - packing
- tt060_py.txt - event binding
- tt070_py.txt - "focus" and binding a widget to keyboard events
- tt074_py.txt - command binding
- tt075_py.txt - using event binding and command binding together
- tt076_py.txt - sharing information among event handlers
- tt077_py.txt - passing arguments to event handlers (part 1) - the problem
- tt078_py.txt - passing arguments to event handlers (part 2) - solving it with lambda
- tt079_py.txt - passing arguments to event handlers (part 3) - solving it with currying
- tt080_py.txt - widget options and pack settings
- tt090_py.txt - nesting frames
- tt095_py.txt - Window Manager methods & controlling the size of windows with the geometry option
- tt100_py.txt - pack options: side, expand, fill, anchor
Tkinter
Tcl and Tk
This is a problem that puzzles many beginning Tkinter programmers. Frederik Lundh has the answer.
From: bmgz (bmgz@dev.null) Subject: Tk -- stupid blank dialog opens up in background Newsgroups: comp.lang.python Date: 2003-12-13 02:38:17 PSTI 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?
From: Fredrik Lundh (fredrik@pythonware.com)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() # won't need thisIf you're building a full-blown Tkinter application, the usual approach is to put your widgets in the root window:
root = Tkinter.Tk() mybutton = Button(root, text=...) mybutton.pack() # etc