Chapter 16. Graphical user interfaces

 

This chapter covers

  • Installing Tkinter
  • Starting and using Tkinter
  • Understanding the principles of Tk
  • Writing a simple Tkinter application
  • Creating and placing widgets
  • Alternatives to Tkinter

This chapter, an introduction to programming GUIs in Python, will do two things. First, it will provide a look at the GUI package that comes with Python, taking into account things like its ease of use, the capabilities of the package, cross-platform portability, and so forth. Second, it will give a brief overview of what else is available for GUI programming with Python and how to find it.

The Python core language has no built-in support for GUIs. It’s a pure programming language, like C, Perl, or Pascal. As such, any support for GUIs must come from libraries external to Python, and many such libraries have been developed.

Of all the GUI packages currently available to Python programmers, Tkinter is the one commonly used. Tkinter is an object-oriented layer on top of the Tcl/Tk graphics libraries. The code that drives it is stable, efficient, and well supported. Although it has been knocked for its somewhat plain appearance, in Python 3.1 Tkinter adds support for the new ttk widgets, which greatly improve its look and feel. I feel that it’s a good choice for developing GUIs in Python for several reasons:

16.1. Installing Tkinter

16.2. Starting Tk and using Tkinter

16.3. Principles of Tkinter

16.4. A simple Tkinter application

16.5. Creating widgets

16.6. Widget placement

16.7. Using classes to manage Tkinter applications

16.8. What else can Tkinter do?

16.9. Alternatives to Tkinter

16.10. Summary

sitemap