CHAPTER 10
GUI Coding Techniques
“Building a Better Mousetrap”
This chapter continues our look at building GUIs with Python and the tkinter library
by presenting a collection of more advanced GUI programming patterns and techni-
ques. In the preceding three chapters, we explored all the fundamentals of tkinter itself.
Here, our goal is to put them to work to add higher-level structures that will be useful
in larger programs. That is, our focus shifts here to writing code of our own which
implements utility above and beyond the basic tkinter toolkit—utility that we’ll ac-
tually find useful in more complete examples later in the book.
Some of the techniques we will be studying in this chapter are as follows:
- Providing common GUI operations in “mixin” classes
- Building menus and toolbars from data structure templates
- Adding GUI interfaces to command-line tools
- Redirecting input and output streams to GUI widgets
- Reloading GUI callback handlers on the fly
- Wrapping up and automating top-level window interfaces
- Using threads and queues to avoiding blocking in GUIs
- Popping up GUI windows on demand from non-GUI programs
- Adding GUIs as separate programs with sockets and pipes
As with other chapters in this book, this chapter has a dual agenda—not only will we
be studying GUI programming, but we’ll also be learning more about general Python
development concepts such as object-oriented programming (OOP) and code reuse.
As we’ll see, by coding GUI tools in Python, it’s easy to apply them in a wide variety
of contexts and programs.
As a segue to the next chapter, this one also closes with a look at the PyDemos and
PyGadgets launcher toolbars—GUIs used to start larger GUI examples. Although most
597
Do
wnload from Wow! eBook <www.wowebook.com>