Setting application-wide default fonts tkinter root window

ぃ、小莉子 提交于 2021-02-11 12:25:46

问题


I am trying to a create an optionDB file which should be of the type.Xdefaults in order to read into a Python Tkinter program to override the Windows system fonts. The idea was presented in the Tkinter book by Grayson on page 49.

1) Create a file called optionDB of type Xdefaults

2) type in the following code

root = Tk()
root.option_readfile('optionDB')

At this point, a new font should override the system default.

The optionDB file has the following line of code in it -

*font: Verdana 10

I cannot read the file for the following reason - Notepad keeps appending a .txt - I have tried optionDB which removes .txt but still cannot find the files even if just named optionDB with no file extension.

Question:

How do I create a '?Xdeaults' file ad read it correctly through the above code. I have tried typing 'optionDB.Xdefaults' as well, and in all cases Tkinter returned a cannot open file error.


回答1:


You can name the file anything you want -- the .txt is harmless. Just make sure that you give the actual filename to option_readfile.

root.option_readfile('optionDB.txt')

Like with just about any file argument, python will look in the current working directory unless you specifically tell it to look somewhere else.



来源:https://stackoverflow.com/questions/36022777/setting-application-wide-default-fonts-tkinter-root-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!