问题
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