Open In App

Changing the colour of Tkinter Menu Bar

Last Updated : 07 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites: Tkinter

Menus are an important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipulating data. Toplevel menus are displayed just under the title bar of the root or any other toplevel windows. 

Changing the color of menubar is not available on the Windows. This is because the menubar is not owned by Tkinter itself, but it is outsourced from other third-parties, hence providing the users limited options only. But if are using Linux, then you are all set to go. You can change the color of menubar by setting the background color and foreground color. Just read the article given below to know more in detail.

Syntax:

menubar = Menu(app, background=’#background color’, fg=’#text color’)

Here, the color to be added to the menubar is given as input to the background parameter. Given below is the proper example to do the same.

Program:

Python




# Import the library tkinter
from tkinter import *
  
# Create a GUI app
app = Tk()
  
# Set the title and geometry to your app
app.title("Geeks For Geeks")
app.geometry("800x500")
  
# Create menubar by setting the color
menubar = Menu(app, background='blue', fg='white')
  
# Declare file and edit for showing in menubar
file = Menu(menubar, tearoff=False, background='yellow')
edit = Menu(menubar, tearoff=False, background='pink')
  
# Add commands in in file menu
file.add_command(label="New")
file.add_command(label="Exit", command=app.quit)
  
# Add commands in edit menu
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
  
# Display the file and edit declared in previous step
menubar.add_cascade(label="File", menu=file)
menubar.add_cascade(label="Edit", menu=edit)
  
# Displaying of menubar in the app
app.config(menu=menubar)
  
# Make infinite loop for displaying app on screen
app.mainloop()


Output:

change menu color


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads