background, and with a font that’s very different from what we’ve seen so far. In fact,
this script customizes the label in a number of ways:
Color
By setting the bg option of the label widget here, its background is displayed in
black; the fg option similarly changes the foreground (text) color of the widget to
yellow. These color options work on most tkinter widgets and accept either a sim-
ple color name (e.g., 'blue') or a hexadecimal string. Most of the color names you
are familiar with are supported (unless you happen to work for Crayola). You can
also pass a hexadecimal color identifier string to these options to be more specific;
they start with a # and name a color by its red, green, and blue saturations, with
an equal number of bits in the string for each. For instance, '#ff0000' specifies
eight bits per color and defines pure red; “f” means four “1” bits in hexadecimal.
We’ll come back to this hex form when we meet the color selection dialog later in
this chapter.
Size
The label is given a preset size in lines high and characters wide by setting its
height and width attributes. You can use this setting to make the widget larger than
the tkinter geometry manager would by default.
Font
This script specifies a custom font for the label’s text by setting the label’s font
attribute to a three-item tuple giving the font family, size, and style (here: Times,
20-point, and bold). Font style can be normal, bold, roman, italic, underline, over
strike, or combinations of these (e.g., “bold italic”). tkinter guarantees that Times,
Courier, and Helvetica font family names exist on all platforms, but others may
work, too (e.g., system gives the system font on Windows). Font settings like this
work on all widgets with text, such as labels, buttons, entry fields, listboxes, and
Text (the latter of which can even display more than one font at once with “tags”).
The font option still accepts older X-Windows-style font indicators—long strings
with dashes and stars—but the newer tuple font indicator form is more platform
independent.
Figure 8-1. A custom label appearance
Configuring Widget Appearance| 417