Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 views
in Technique[技术] by (71.8m points)

python - Changing the colour of tkinter 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?

enter image description here

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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...