Created
January 25, 2022 11:33
-
-
Save StefRe/3ec99394f90def431e19e06534c7e60e to your computer and use it in GitHub Desktop.
Tkinter Standard Fonts and How to Scale them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
import tkinter.font | |
root = tk.Tk() | |
print('Standard fonts:') | |
for name in sorted(tk.font.names()): | |
config = tk.font.Font(name=name, exists=True).config() | |
print(f"{name:20.20}: {config['family']} {config['size']} {config['weight']}") | |
# increase all fonts by given factor | |
factor = 2.5 | |
for name in sorted(tk.font.names()): | |
font = tk.font.Font(name=name, exists=True) | |
font.configure(size=round(font.cget('size') * factor)) | |
print(f'\nStandard fonts scaled by factor {factor}:') | |
for name in sorted(tk.font.names()): | |
config = tk.font.Font(name=name, exists=True).config() | |
print(f"{name:20.20}: {config['family']} {config['size']} {config['weight']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Standard fonts on Windows 10
tk.TkVersion 8.6
(Python 3.8.2):Font documentation