我一直在努力更改下面菜单类中"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/