You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Tkinter组件菜单栏的背景颜色?

Tkinter菜单栏背景颜色修改失效(Win10系统)

在Win10系统下,我用Tkinter创建GUI时,已经通过StackOverflow上的非Win10专用方案成功修改了窗口标题栏颜色,但菜单栏的背景颜色始终无法修改。

我尝试给Menu组件设置bg、fg、activebackground等属性,但菜单栏外观完全没有变化,还是系统默认样式。相关代码如下:

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

实际运行后,菜单栏的背景色、文字颜色等都没有按代码设置的生效,和窗口黑色背景形成明显反差。

内容的提问来源于stack exchange,提问作者OverRevvv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 06:25:10