简体   繁体   中英

Setting application-wide default fonts tkinter root window

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM