How to set a Tkinter widget to a monospaced, platform independent font? How to set a Tkinter widget to a monospaced, platform independent font? tkinter tkinter

How to set a Tkinter widget to a monospaced, platform independent font?


Standard fonts (including TkFixedFont) can only be given as a plain string, not as a tuple. I.e. font='TkFixedFont' works, while font=('TkFixedFont',) (note the parentheses and comma) will not.

This seems to be the general case. I tried it with both Tkinter.Button and ttk.Style.

For styles that means:

import Tkinterimport ttk# will use the default (non-monospaced) fontbroken = ttk.Style()broken.configure('Broken.TButton', font=('TkFixedFont', 16))# will work but use Courier or something resembling itcourier = ttk.Style()courier.configure('Courier.TButton', font=('Courier', 16))# will work nicely and use the system default monospace fontfixed = ttk.Style()fixed.configure('Fixed.TButton', font='TkFixedFont')

Tested to work with Python 2.7 on both Linux and Windows.

Bottom line is that the code in the question will work perfectly fine if just the parentheses around "TkFixedFont" were removed.