Reputation: 361
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()
Upvotes: 3
Views: 16079
Reputation: 23
To follow on from Brian Oakley's response. The menu bar on Linux (at least on my Linux Mint installation) renders the desired color.
Upvotes: 2
Reputation: 111
On Linux it is possible:
def main():
root =Tk()
menubar = Menu(root, background='lightblue', foreground='black',
activebackground='#004c99', activeforeground='white')
file = Menu(menubar, tearoff=1, background='lightblue', foreground='black')
file.add_command(label="Receive")
file.add_command(label="Issue")
file.add_command(label="Track")
file.add_command(label="Search")
file.add_command(label="Allocate")
file.add_separator()
file.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Goods", menu=file)
edit = Menu(menubar, tearoff=0)
edit.add_command(label="Undo")
edit.add_separator()
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
edit.add_command(label="Delete")
edit.add_command(label="Select All")
menubar.add_cascade(label="Accounts", menu=edit)
help = Menu(menubar, tearoff=0)
help.add_command(label="About")
menubar.add_cascade(label="Help", menu=help)
root.config(menu=menubar)
ex = MainWin()
root.geometry("2000x1391")
root.mainloop()
if __name__ == '__main__':
main()
Just add foreground and background attributes.
Upvotes: 2
Reputation: 385970
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.
Upvotes: 11