How to change the background color of menubar of Tkinter Widget

697 Views Asked by At

I'm trying to change the background color of the menubar that I made using the Tkinter widget, I changed the background color of the title-bar thanks to a solution that I came across on StackOverflow even tho it wasn't for windows 10 but it worked in my windows 10 however it's not able to change the color of the menubar.

Here's the code including the function to change title-bar.


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

When i tried to customize the menubar it didn't worked as it's shown in this screenshot, Background and other colors are suppose to change but it didn't. Screenshot

1

There are 1 best solutions below

0
On BEST ANSWER

I'm trying to change the background color of the menubar that I made using the Tkinter widget.

Try this.

import tkinter as tk

 
class MenuBar(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master, bd=1, relief='raised')
        self.master=master
        self.configure(background='orange', cursor='hand2')

        file = tk.Menubutton(self, text='File',
                             background='black',
                             foreground='red',
                             activeforeground='black',
                             activebackground='white'
                             )
        file_menu = tk.Menu(file,tearoff=0)
        file_menu.add_command(label='save', 
                              background='black',
                              foreground='white',
                              activeforeground='black',
                              activebackground='white'
                              )
        
        file.config(menu=file_menu)
        file.pack(side='left')

        edit = tk.Menubutton(self, text='Edit',
                             background='blue',
                             foreground='white',
                             activeforeground='black',
                             activebackground='white'
                             )
        edit_menu = tk.Menu(edit,tearoff=0)
        edit_menu.add_command(label='add',
                              background='black',
                              foreground='white',
                              activeforeground='black',
                              activebackground='white'
                              )

        edit.config(menu=edit_menu)
        edit.pack(side='left')

         

 
root = tk.Tk()
menubar = MenuBar(root)
menubar.pack(side='top', fill='x')
root.mainloop()

Output before:

enter image description here

Output after:

enter image description here