Tkinter Widget Font
The font parameter is used to set the text glyph. This parameter contains the following.
(1) font family
: such as Helvetica, Times, etc., the reader can enter Word within the reference to all the system font.
(2) font size
: the unit is pixels.
(3) weight
: such as bold, normal.
(4) slant
: such as italic, roman, if not italic is roman.
(5) underline
: for example, True, False.
(6) overstrike
: e.g. True, False.
Tkinter Widget Font Example
Use Helvetic font, size is 20, bold display.
from tkinter import *
root = Tk()
root.title("apidemos.com")
label = Label(root,text="Welcome to apidemos.com",
fg="red",bg="yellow",
height=3,width=30,
font=("Helvetic",20,"bold"))
# Use Helvetic glyphs, size 20, bold display.
label.pack() # Packaging and positioning components
# print(type(label)) # <class 'NoneType'>
root.mainloop()
Output:
From the above figure you can see that the label area is enlarged, this is because the program line 7 height and width are linked with the font size. In addition, you can also use the tuple way to handle the font parameter in line 8.
from tkinter import *
root = Tk()
root.title("apidemos.com")
label = Label(root,text="Welcome to apidemos.com",
fg="red",bg="yellow",
height=3,width=30,
font="Helvetic 20 bold")
# Use Helvetic glyphs, size 20, bold display.
label.pack() # Packaging and positioning components
# print(type(label)) # <class 'NoneType'>
root.mainloop()
Output: