Examining a GUI


Before I describe how to program a GUI, I want to define all of the GUI elements you'll meet in this chapter. Figure 10.4 shows off the Mad Lib program, though this time the various elements are labeled.

click to expand
Figure 10.4: You'll learn to create all of these GUI elements.

To create a GUI with Python, you need to use a GUI toolkit. There are many to pick from, but I use the Tkinter toolkit in this chapter. Tkinter is cross-platform and the most popular Python GUI toolkit around.

HINT

If you're running an operating system other than Windows, you may need to download and install additional software to use the Tkinter toolkit. To find out more, visit the Python Web site's Tkinter page at http://www.python.org/topics/tkinter.

You create GUI elements by instantiating objects from classes of the Tkinter module, which is part of the Tkinter toolkit. Table 10.1 describes each GUI element from Figure 10.4 and lists its corresponding Tkinter class.

Table 10.1: SELECTED GUI ELEMENTS

Element

Tkinter Class

Description

Frame

Frame

Holds other GUI elements

Label

Label

Displays uneditable text or icons

Button

Button

Performs an action when the user activates it

Text entry

Entry

Accepts and displays one line of text

Text box

Text

Accepts and displays multiple lines of text

Check button

Checkbutton

Allows the user to select or not select an option

Radio button

Radiobutton

Allows, as a group, the user to select one option from several

HINT

There's no need to memorize all of these Tkinter classes. I just want to give you an overview of the classes that you learn about in this chapter.




Python Programming for the Absolute Beginner
Python Programming for the Absolute Beginner, 3rd Edition
ISBN: 1435455002
EAN: 2147483647
Year: 2003
Pages: 194

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net