Python and Tkinter Programming
Author: John E. Grayson
Price: $49.95 US
Reviewer: Phil Hughes
Let's start with the conclusion: if you intend to work with Tkinter, buy this book. If you need to do graphical programming in Python but don't know what tools to use, buy this book. Now that the hard part of the review is done, let me give you a little background on my Tk experiences, and then get on to the details of the book.
About five years ago, armed with John Osterhout's book, Tcl and the TK Toolkit I started to play with Tcl and Tk. While I appreciated how you could toss together something very quickly, I was also very frustrated by Tcl. It just didn't feel like a real programming language. There was always the need for a “trick” to accomplish what I wanted. Because of this bad feeling, I never did much with Tcl and Tk.
Last year, when I interviewed Guido van Rossum, I asked him about toolkits for doing graphical programming in Python, and he recommended Tkinter. He also pointed out that the current problem was a lack of good documentation. Python and Tkinter has addressed that problem, and done a fine job as well.
The book assumes the reader has a basic knowledge of Python, but requires no knowledge of Tcl or Tk. The first part, only 28 pages, is a quick review of Python, an intro to Tkinter and a sample application. Thus, by page 28, you will be convinced that you, too, could write a calculator or two. Even in this introductory chapter, the author does an excellent job of discussing the various sections of the code.
The next part, titled “Displays”, goes on for close to 300 pages. This is the meat of the book, covering all the things you will need to build your application. First, widgets are covered, including Pmw (Python MegaWidgets) and then geometry managers. By the end of these two chapters, you should be pretty comfortable putting up any sort of widget you want and getting the screen organized.
Each concept is presented with some explanatory text, some code and a screen shot. The code is on track for teaching you the next thing you need to know, rather than being just a book of sample code. Part of the credit goes to Python itself, where you can write something useful in a few lines, but the author has done a good job of breaking up the material so that a concept can be presented in only a few pages.
The next chapter, titled “Using Classes, Composites and Special Widgets”, gets you seriously using structured programming techniques to develop your application. While this is a little scary for those of us who grew up on FORTRAN and moved to C, it is well worth embracing if you want to be a good Python programmer.
The next four chapters take you through drawing all sorts of objects. First there are “Dialogs and Forms”, where you finish up with a really fancy calculator. Next is “panels and Machines”, where you learn how to do very complex graphics models. A digital multimeter complete with rotary selector switch is one such example. The next two chapters cover more free-form drawing and finally charts and graphs. The part ends with a short chapter on the window manager.
Part three, titled “Putting it All Together...”, is a catch-all for the other things you need to know. This includes extending Python, debugging and issues of performance and style. The part ends with a chapter on distributing Tkinter applications.
The remainder of the book, over 250 pages, consists of appendices. This seems to be the tradition for most Python books. It makes sense, due to the lack of printed reference documentation on Python.
The first appendix is called “Mapping Tk to Tkinter”. If you have an existing application in Tk that you want to port, this is where you will find all the answers. It can also provide some help if you are familiar with Osterhout's book and want a quick translation guide.
Appendix B is a Tkinter reference. The reference includes descriptions of the classes, along with detailed descriptions of all options. When appropriate, graphics are also included.
Appendix C is a reference on Python megawidgets. Like the previous appendix, the descriptions are detailed and graphics are included when needed.
Appendix D covers building and installing Python and Tkinter. Information is included for UNIX and MS-Windows, with a brief mention of MacOS.
The appendices end with three short sections: Events and keysyms, Cursors and References. While each appendix is very brief, it covers important topics.
The book ends with a comprehensive index. As I said in the beginning, if you are going to work with Tkinter, buy this book. I'm not saying this because it is the only book out there. It is well organized, easy to read and offers a great tutorial combined with a comprehensive reference.
- On Your Marks, Get Set...Gutsy Gibbon!
- VMware's Clarity Design System
- Let's Go to Mars with Martian Lander
- Applied Expert Systems, Inc.'s CleverView for TCP/IP on Linux
- Papa's Got a Brand New NAS
- My Childhood in a Cigar Box
- Raspberry Pi: the Perfect Home Server
- Returning Values from Bash Functions
- OpenSSL Hacks
- Simplenote, Simply Awesome!