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 techniques. In the last 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. 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 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.
Two notes before we begin: first, be sure to read the code listings in this chapter for details we won’t present in the narrative. Second, although small examples that apply in this chapter’s techniques will show up along the way, more realistic application will have to await more realistic programs. We’ll put these techniques to use in the larger examples in the next chapter and throughout the rest of the book. In fact, we’ll be reusing the modules we develop here often, as tools in other programs in this book; reusable software wants to be reused. For now, though, let’s do what our species does best and build some tools.
3.147.67.16