更改 tkinter 菜单栏的颜色 [英] Changing the colour of tkinter menubar

查看:122
本文介绍了更改 tkinter 菜单栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我要做的是将菜单栏的颜色更改为与我的窗口相同.我已经尝试了您在下面看到的内容,将 bg="#20232A" 添加到 menubar 但这似乎没有影响..

I have the following code, what I'm trying to do is change the color the the menubar to be the same as my window. I have tried what you see below, adding to bg="#20232A" to menubar but this seems to have no affect..

我的问题:下图是窗口(尽管是窗口的一部分),它同时展示了菜单栏和背景.我希望菜单栏与下面看到的背景颜色相同,我该如何实现?

My Question: The below image is the window (albeit a snippet of the window), it showcases both the menubar and background. I want the menubar to be the same color as the background seen below, how can I achieve this?

from tkinter import *

config = {"title":"Editor", "version":"[Version: 0.1]"}

window = Tk()
window.title(config["title"] + " " +config["version"])
window.config(bg="#20232A")
window.state('zoomed')

def Start():
    menubar = Menu(window, borderwidth=0, bg="#20232A") # Tried adding background to this, but it doesent work

    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="Open")
    filemenu.add_command(label="Save")
    menubar.add_cascade(label="File", menu=filemenu)
    window.config(menu=menubar)

Start()
window.mainloop()

推荐答案

您无法在 Windows 或 OSX 上更改菜单栏的颜色.尽管我不确定,但在 linux 上的某些窗口管理器上可能是可能的.

You cannot change the color of the menubar on Windows or OSX. It might be possible on some window managers on linux, though I don't know for certain.

原因是菜单栏是使用不受 tkinter 管理的本机小部件绘制的,因此您仅限于平台允许的内容.

The reason is that the menubar is drawn using native widgets that aren't managed by tkinter, so you're limited to what the platform allows.

这篇关于更改 tkinter 菜单栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆