Re: Force tkinter to use another fixed font
Sibylle Koczian <[email protected]> Tue, 28 Jul 2020 10:23:59 +0200
| Newsgroups | gmane.comp.python.tkinter |
|---|---|
| Message-ID | <[email protected]> |
Am 22.07.2020 um 18:36 schrieb Sibylle Koczian:
> Am 21.07.2020 um 18:30 schrieb Paul Malherbe:
>> Hi
>>
>> ttk.Entry and ttk.Label use TkDefaultFont therefore changing TkFixedFont
>> will not work.
>>
> Thank you for making me look at this - it's even worse: ttk.Label uses
> TkDefaultFont, ttk.Entry uses TkTextFont. So that's definitely not the
> right way.
>
No, I think now it _is_ a comparatively simple way:
import tkinter as tk
from tkinter import ttk
from tkinter import font
def changefonts():
for fontname in [f for f in font.names()
if font.nametofont(f).actual()["family"] ==
"Inconsolata"]:
font.nametofont(fontname).config(
family="Bitstream Vera Sans Mono")
def main():
root = tk.Tk()
changefonts()
###... build your gui
root.mainloop()
if __name__ == "__main__":
main()
This should work for all themes. It seems unnecessary on Windows and on
Linux problems with the fonts probably depend on the chosen desktop
manager.
Regards
Sibylle