5

Many sites say the Menu widget has an option 'font', but I've been unable to set it. System is Python 3.5 running in Windows 8.1 . Script starts:

  1. from tkinter import *
  2. root = Tk()
  3. root.geometry('1400x800+120+40')
  4. .
  5. .
  6. menubar = Menu(root)

All lines below have failed :

1. root.configure(font = ('Verdana',14))
2. root.option_add("*Font", ('Verdana', 14))
3. menubar = Menu(root, font = ('Verdana', 14))
4. menubar.configure(font = ('Verdana', 14))
5. menubar.add_command(label = "File", font = ('Verdana', 14))
6. default_font = Font.nametofont('Verdana')
7. default_font.configure(size = 14)

*Most of above give error " unknown option 'font' "*    
dlemper
  • 219
  • 3
  • 6
  • 1
    This question was asked [here](http://stackoverflow.com/questions/31925771/python-tkinter-how-to-modify-the-font-of-the-menu-widget) without an answer but it looks like it isn't possible to change the menu font on Windows and OSX. – scotty3785 Jan 03 '17 at 11:20

4 Answers4

3

Thanks scotty3785. Solved by changing the Menu font in Windows :

Windows System > Control Panel > Appearance > Display > Change Text Size > choose Menus

Now the menu font of tkinter is larger.

Might be said that Python's tkinter is not completely cross-platform.

dlemper
  • 219
  • 3
  • 6
3

I fixed by changing

root.option_add("*Font", ('Verdana', 14))

to

root.option_add("*Font", 'Verdana 14')

:)

code_San
  • 35
  • 4
2

Here's how to change the font:

menubar.config("Verdana", 14)

menubar.add_command(label="Something", font=("Verdana", 14))

  • 2
    Does not work on Windows 10: TypeError: configure() takes from 1 to 2 positional arguments but 3 were given. The other method works but does not change anything. – ViktorMS Nov 06 '19 at 20:21
1

I was able to change a menu item's font, in Python 3.6, using a custom font as described in this post:

How to change a widget's font style without knowing the widget's font family/size?

Here is an example of adding a custom font to a tk menu instance:

default_font = tkfont.nametofont("TkDefaultFont")
custom_font = tkfont.Font(family=default_font['family'], size=default_font['size'])
menu.add_command(label="Something", command=do_something, font=custom_font)
tfv
  • 6,016
  • 4
  • 36
  • 67