![](/img/trans.png)
[英]How to change the background color of tkinter ttk.PanedWindow widget?
[英]How to change the background color of menubar of Tkinter Widget
我正在尝试更改使用 Tkinter 小部件制作的菜单栏的背景颜色,我更改了标题栏的背景颜色,这要归功于我在StackOverflow上遇到的解决方案,即使它不是 windows 10 但是它在我的 windows 10 中工作,但是它无法更改菜单栏的颜色。
这是包含 function 的代码,用于更改标题栏。
from tkinter import *
import ctypes as ct
root = Tk()
root.title("MenuBar in GUI")
root.geometry("500x500")
root.config(bg="black")
# These attributes are not working, menubar still remains unchanged
menubar = Menu(root, bg='black', fg='cyan', activebackground="grey",activeforeground="cyan")
filemenu = Menu(menubar, bg="black", fg="purple",activebackground="grey", activeforeground="cyan", tearoff=False)
menubar.add_cascade(label="File", menu=filemenu)
root.config(bg="black", menu=menubar) # Defining the main menu
root.mainloop()
当我尝试自定义菜单栏时,它没有像这个屏幕截图中所示那样工作,背景和其他 colors 应该改变但它没有。 截屏
试试这个:
from tkinter import *
app = Tk()
app.title("GThe color of menubar of Tkinter Widget")
app.geometry("800x500")
menubar = Menu(app, background='blue', fg='white')
file = Menu(menubar, tearoff=False, background='yellow')
edit = Menu(menubar, tearoff=False, background='pink')
file.add_command(label="New")
file.add_command(label="Exit", command=app.quit)
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
menubar.add_cascade(label="File", menu=file)
menubar.add_cascade(label="Edit", menu=edit)
app.config(menu=menubar)
app.mainloop()
Output 图片:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.