Ed_F
Ed_F

Reputation: 185

Change font of tkinter menu

I've been struggling to change the font of the 'File' button in the menu class below.

The self.config(font=self.font) doesn't work nor does add_cascade(font=self.font)

I'm using Windows 10.

Any help much appreciated!

from tkinter import *
import sys

class DatabaseMenu(Menu):
    """Menu for configuring database"""

    def __init__(self, parent, callbacks, **kwargs):
        super().__init__(parent)
        self.callbacks = callbacks
        self.font = ("Calibri", 15)
        self.config(font=self.font)
        self._build_menu()


    def _build_menu(self):

        self.file_menu = Menu(self, tearoff=False)
        self.file_menu.add_command(
            label="Change database structure",
            command=self.callbacks['file->change_database_structure'],
            font=self.font
            )

        self.add_cascade(label=' File ', menu=self.file_menu, font=self.font)

if __name__ == '__main__':
    root = Tk()
    menu = DatabaseMenu(root, {'file->change_database_structure':sys.exit})
    root.config(menu=menu)
    root.mainloop()

Upvotes: 1

Views: 468

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386030

You cannot change the font of the menubar or its menus with tkinter. Those menus are rendered by the underlying OS rather than being rendered by tkinter.

Upvotes: 1

Related Questions