Reputation: 122
I'm setting up a simple program with Tkinter and am trying to use a custom font. I create the font using
myFont = tkinter.font.Font(family='<familyName>')
I want to use a fallback font if familyName isn't available on the user's computer. However, Tkinter doesn't raise an error or give any feedback if familyName isn't available and instead just uses the default font.
How do I handle this?
Upvotes: 0
Views: 433
Reputation: 19144
tinter.font.families()
returns a tuple of available families so you can check availability before calling Font. Note that one must not only import tkinter.font
first, but as of 3.4.3, at least, create a root window before calling either Font
or families
.
The official tkinter doc has no section on tkinter.font. Two other useful utilities are names()
(of defined fonts) and nametofont(name)
.
Upvotes: 1