[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

CHAPTER 7


Graphical User Interfaces


“Here’s Looking at You, Kid”


For most software systems, a graphical user interface (GUI) has become an expected
part of the package. Even if the GUI acronym is new to you, chances are that you are
already familiar with such interfaces—the windows, buttons, and menus that we use
to interact with software programs. In fact, most of what we do on computers today is
done with some sort of point-and-click graphical interface. From web browsers to sys-
tem tools, programs are routinely dressed up with a GUI component to make them
more flexible and easier to use.
In this part of the book, we will learn how to make Python scripts sprout such graphical
interfaces, too, by studying examples of programming with the tkinter m o d u l e , a p o r t-
able GUI library that is a standard part of the Python system and the toolkit most widely
used by Python programmers. As we’ll see, it’s easy to program user interfaces in Python
scripts thanks to both the simplicity of the language and the power of its GUI libraries.
As an added bonus, GUIs programmed in Python with tkinter are automatically port-
able to all major computer systems.

GUI Programming Topics


Because GUIs are a major area, I want to say a few more words about this part of the
book before we get started. To make them easier to absorb, GUI programming topics
are split over the next five chapters:


  • This chapter begins with a quick tkinter tutorial to teach coding basics. Interfaces
    are kept simple here on purpose, so you can master the fundamentals before mov-
    ing on to the following chapter’s interfaces. On the other hand, this chapter covers
    all the basics: event processing, the pack g e o m e t r y m a n a g e r , u s i n g i n h e r i t a n c e a n d
    composition in GUIs, and more. As we’ll see, object-oriented programming (OOP)
    isn’t required for tkinter, but it makes GUIs structured and reusable.


355

Do


wnload from Wow! eBook <www.wowebook.com>

Free download pdf