有没有办法在 Tkinter 菜单中更改选定的字体颜色?
Is there a way to change the selected font color in a Tkinter menu?
有什么方法可以更改 Tkinter 中菜单项的选定字体颜色吗?我以为它是 selectcolor 但我无法让它做任何事情。将不胜感激。
当我将光标悬停在 "Save" 文本上方时,我希望它保持黑色。我现在只是使用 effbot.org 的示例代码:
from tkinter import *
root = Tk()
def hello():
print("hello!")
menubar = Menu(root)
# create a pulldown menu, and add it to the menu bar
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=hello)
filemenu.add_command(label="Save", command=hello)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
# create more pulldown menus
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=hello)
editmenu.add_command(label="Copy", command=hello)
editmenu.add_command(label="Paste", command=hello)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)
# display the menu
root.config(menu=menubar)
root.mainloop()
有 activebackground
和 activeforeground
选项,您可以使用这些选项更改悬停时的背景和前景色。
替换这个
filemenu.add_command(label="Save", command=hello)
有了这个
filemenu.add_command(label="Save", command=hello, activeforeground = 'black')
希望这能按预期工作:)
有什么方法可以更改 Tkinter 中菜单项的选定字体颜色吗?我以为它是 selectcolor 但我无法让它做任何事情。将不胜感激。
当我将光标悬停在 "Save" 文本上方时,我希望它保持黑色。我现在只是使用 effbot.org 的示例代码:
from tkinter import *
root = Tk()
def hello():
print("hello!")
menubar = Menu(root)
# create a pulldown menu, and add it to the menu bar
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=hello)
filemenu.add_command(label="Save", command=hello)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
# create more pulldown menus
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=hello)
editmenu.add_command(label="Copy", command=hello)
editmenu.add_command(label="Paste", command=hello)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)
# display the menu
root.config(menu=menubar)
root.mainloop()
有 activebackground
和 activeforeground
选项,您可以使用这些选项更改悬停时的背景和前景色。
替换这个
filemenu.add_command(label="Save", command=hello)
有了这个
filemenu.add_command(label="Save", command=hello, activeforeground = 'black')
希望这能按预期工作:)