Let's start by changing the size, weight, slant, and family of the font used to display text. To specify the size, we provide the height as an integer in points. We can set the weight to either bold or normal and the slant to either italic (slanted) or roman (not slanted).
The font families we can use depend on what system the program is running on. common families include Times, courier, and Verdana, but dozens of others are usually available. One note of caution, though: if you choose an unusual font, people running your program on other computers might not have it, so your GUI might appear different than you'd like for them.
The following sets the font of a button to be 14-point, bold, italic, and Courier. The result is shown in Figure 14.9, on the following page.
from Tkinter import * window = Tk()
button = Button(window, text="Hello", font=("Courier", 14, "bold italic"))
H O Otk
H O Otk
Figure 14.9: A button with customized text font
Was this article helpful?