python - 更改 tkinter 菜单的字体

标签 python tkinter tkinter-menu

我一直在努力更改下面菜单类中"file"按钮的字体。

self.config(font=self.font) 不起作用,add_cascade(font=self.font) 也不起作用

我使用的是 Windows 10。

非常感谢任何帮助!

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()

最佳答案

您无法使用 tkinter 更改菜单栏或其菜单的字体。这些菜单由底层操作系统呈现,而不是由 tkinter 呈现。

关于python - 更改 tkinter 菜单的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319712/

相关文章:

python - 在 3D 图上绘制两个 2D 图

python - 如何在 Python 中对字典列表进行多排序?

combobox - Python 2.7 : Tkinter/ttk Linked ComboBoxes

python - 是否可以更改 tkinter 中菜单的字体?

python - 如何使用键盘快捷键/绑定(bind)激活 tkinter 菜单和工具栏?

python - 在菜单打开时自定义 tkinter 菜单

Python - 如何将列映射到字母序列?

python - 如果在 while 循环内

Python:Tkinter——如何让光标显示忙碌状态

python - Tkinter 给了我一个 _tkinter.TclError : bad event type or keysym "button" when i try to run it