NOTE THAT THIS PAGE IS STILL UNDER DEVELOPMENT. <BR>
I think that all of the links work, but many of them go to the original location of Thinking in Tkinter on www.ferg.org.
They have not yet been moved to sourceforge.<BR>
— Stephen Ferg, 2011-10-26</B>
When I first started trying to learn Tkinter out of various books and online tutorials, I found that it much more difficult than I thought it should be.
The problem was (and still is) that the authors of the books and tutorials typically rushed into telling me about all of the widgets in the Tkinter toolbox, but they never explained basic GUI concepts. They didn't explain how to "think in Tkinter". So I started to write the kind of book that I wished that I could have found.
Naturally, I didn't get too far. This is only the beginning of such a book. But I think it will be useful to beginning Tkinter programmers. And maybe it will inspire others to continue with a similar approach.
<I>Thinking in Tkinter</I> 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 <A HREF="http://www.pythonware.com/library/index.htm">An Introduction to Tkinter</A>, John Shipman's Tkinter reference, and the other useful references at the bottom of this page.
Above all, I must emphasize that <A HREF="http://www.amazon.com/exec/obidos/ASIN/0130220280/qid=1031879522/sr=2- 1/ref=sr_2_1/103-5004459-9331864">Practical Programming in Tcl and Tk</A> by Brent Welch is absolutely essential for working with Tk and Tkinter. <B>Get this book!</B>
Note that you should <U>not</U> 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 -- <U><I>for each program</I></U> -- 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.
<I>Thinking in Tkinter</I> 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.
<A HREF="http://www.graphicmaps.com/clipart.htm"> <IMG SRC="http://www.ferg.org/thinking_in_tkinter/languages/english/usaFlag.gif" title="clipart provided by: www.worldatlas.com" ALT="Flag of USA" align="left" WIDTH="60" HEIGHT="40" BORDER="2"></A> <A HREF="http://www.graphicmaps.com/clipart.htm"> <IMG SRC="http://www.ferg.org/thinking_in_tkinter/languages/english/ukFlag.gif" title="clipart provided by: www.worldatlas.com" ALT="Flag of United Kingdom" align="right" WIDTH="60" HEIGHT="40" BORDER="2"> </A> | <P> <A HREF="all_programs.html"><I>Thinking in Tkinter</I></A> is formatted for reading and printing. For more information, see <A HREF="#fileinfo">below.</A></P> |
<A HREF="http://www.graphicmaps.com/clipart.htm"><IMG SRC="http://www.ferg.org/thinking_in_tkinter/languages/brazil/flagBrazil.gif" title="clipart provided by: www.worldatlas.com" ALT="Flag of Brazil" align="right" WIDTH="60" HEIGHT="40" BORDER="2"></A> | <A HREF="http://www.python.org.br/wiki/PensandoEmTkinter">Pensando em Tkinter</A> — Brazilian/Portugese translation, thanks to J. Labaki, a Ph.D. student at the Department of Computational Mechanics, State University of Campinas, Brazil |
<A HREF="http://www.graphicmaps.com/clipart.htm"><IMG SRC="http://www.ferg.org/thinking_in_tkinter/languages/france/flagFrance.gif" title="clipart provided by: www.worldatlas.com" ALT="Flag of France" align="right" WIDTH="60" HEIGHT="40" BORDER="2"></A> | <A HREF="languages/france/penser_en_tkinter.html">Penser en Tkinter</A> — French translation, thanks to Gérard Labadie |
<A HREF="http://www.graphicmaps.com/clipart.htm"> <IMG SRC="http://www.ferg.org/thinking_in_tkinter/languages/italia/flagItaly.gif" title="clipart provided by: www.worldatlas.com" ALT="Flag of Italy" align="right" WIDTH="60" HEIGHT="40" BORDER="2"></A> | <A HREF="http://linuxdidattica.org/docs/altre_scuole/msm_p/txs_01.html">Tkinter per sopravvivere</A> — Italian translation, thanks to Prof. Massimo Piai |
Click <A HREF="http://www.ferg.org/all_programs.html">HERE</A> to read and print <I>Thinking in Tkinter.</I> This page contains all of the programs, formatted as a single document to facilitate printing and reading. <B>NOTE</B> however that you really have to download and run the programs to get their full benefit.
<H3>How to download all programs in a single ZIP file</H3>You can download a ZIP file containing all of the programs, plus a driver file, by downloading <A HREF="http://www.ferg.org/thinking_in_tkinter.zip">thinking_in_tkinter.zip</A>.
This zip file contains the <I>Thinking in Tkinter</I> Python files, plus a driver program called <TT>thinking.py</TT> and a batch file called <TT>thinking.bat</TT>. 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
thinking
You can look at the individual programs online by clicking on the following links
<UL> <LI><A href="http://www.ferg.org/thinking_in_tkinter/thinking_py.txt">thinking_py.txt</A> - the driver program</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt000_py.txt">tt000_py.txt</A> - introduction</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt010_py.txt">tt010_py.txt</A> - simplest possible Tkinter program: 3 statements</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt020_py.txt">tt020_py.txt</A> - creating a GUI object; packing; containers vs. idgets</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt030_py.txt">tt030_py.txt</A> - creating a widget and putting it in a frame</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt035_py.txt">tt035_py.txt</A> - using a class structure in the program</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt040_py.txt">tt040_py.txt</A> - some other ways to define a widget</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt050_py.txt">tt050_py.txt</A> - packing</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt060_py.txt">tt060_py.txt</A> - event binding</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt070_py.txt">tt070_py.txt</A> - "focus" and binding a widget to keyboard events</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt074_py.txt">tt074_py.txt</A> - command binding</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt075_py.txt">tt075_py.txt</A> - using event binding and command binding together</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt076_py.txt">tt076_py.txt</A> - sharing information among event handlers</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt077_py.txt">tt077_py.txt</A> - passing arguments to event handlers (part 1) - the problem</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt078_py.txt">tt078_py.txt</A> - passing arguments to event handlers (part 2) - solving it with lambda</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt079_py.txt">tt079_py.txt</A> - passing arguments to event handlers (part 3) - solving it with currying</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt080_py.txt">tt080_py.txt</A> - widget options and pack settings</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt090_py.txt">tt090_py.txt</A> - nesting frames</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt095_py.txt">tt095_py.txt</A> - Window Manager methods & controlling the size of windows with the <I>geometry</I> option</LI> <LI><A href="http://www.ferg.org/thinking_in_tkinter/tt100_py.txt">tt100_py.txt</A> - pack options: side, expand, fill, anchor</LI> </UL>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, Stephen Ferg, 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.
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.