Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有办法更改Tkinter菜单中选定的字体颜色?_Python_User Interface_Tkinter_Tkinter Menu - Fatal编程技术网

Python 有没有办法更改Tkinter菜单中选定的字体颜色?

Python 有没有办法更改Tkinter菜单中选定的字体颜色?,python,user-interface,tkinter,tkinter-menu,Python,User Interface,Tkinter,Tkinter Menu,有没有办法更改Tkinter中菜单项的选定字体颜色?我以为它是selectcolor,但我没能让它做任何事情。非常感谢您的帮助 当我将光标悬停在“保存”文本上时,我希望它保持黑色。我现在只使用effbot.org的示例代码: from tkinter import * root = Tk() def hello(): print("hello!") menubar = Menu(root) # create a pulldown menu, and add it to the me

有没有办法更改Tkinter中菜单项的选定字体颜色?我以为它是selectcolor,但我没能让它做任何事情。非常感谢您的帮助

当我将光标悬停在“保存”文本上时,我希望它保持黑色。我现在只使用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')

希望它能像预期的那样工作:)

activebackground
activeforeground
选项,您可以使用这些选项更改悬停时的背景和前景颜色

替换这个

filemenu.add_command(label="Save", command=hello)
用这个

filemenu.add_command(label="Save", command=hello, activeforeground = 'black')
希望这能如预期的那样起作用:)

相关的a