Changing the colour of Tkinter Menu Bar
Last Updated :
07 Apr, 2021
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
from tkinter import *
app = Tk()
app.title( "Geeks For Geeks" )
app.geometry( "800x500" )
menubar = Menu(app, background = 'blue' , fg = 'white' )
file = Menu(menubar, tearoff = False , background = 'yellow' )
edit = Menu(menubar, tearoff = False , background = 'pink' )
file .add_command(label = "New" )
file .add_command(label = "Exit" , command = app.quit)
edit.add_command(label = "Cut" )
edit.add_command(label = "Copy" )
edit.add_command(label = "Paste" )
menubar.add_cascade(label = "File" , menu = file )
menubar.add_cascade(label = "Edit" , menu = edit)
app.config(menu = menubar)
app.mainloop()
|
Output:
Please Login to comment...