
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the menu background color of Tkinter's OptionMenu widget?
Consider a scenario where we need something to display a menu with some choices in the form of a dropdown list. To achieve this particular feature, Tkinter provides an OptionMenu widget which consists of features to add choices and a list of items in it. We can set up the default behavior of the OptionMenu widget by configuring its property such as background color, width, height, foreground color, etc.
Example
# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Add a Label Label(win, text="Select a Day from the Menu", font=('Aerial 13')).pack(pady=10) # Create a Variable to store the selection var = StringVar() # Create an OptionMenu Widget and add choices to it option = OptionMenu(win, var, "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") option.config(bg="gray81", fg="white") option['menu'].config(bg="green3") option.pack(padx=20, pady=30) win.mainloop()
Output
Running the above code will display an OptionMenu having Days as the choices. The Menu has some background color and foreground color which can be changed in the configuration method.
- Related Questions & Answers
- Dynamically change the widget background color in Tkinter
- How to change a Tkinter widget's font style without knowing the widget's font family/size?
- How to change the background color of the options menu in Android?
- How to change the background color of a Treeview in Tkinter?
- How to change the background color of a tkinter Canvas dynamically?
- How do I get the background color of a Tkinter Canvas widget?
- How to call a function using the OptionMenu widget in Tkinter?
- How to change the color of certain words in a Tkinter text widget?
- How to set a widget's size in Tkinter?
- How to make a Button Hover to change the Background Color in Tkinter?
- How to get the Tkinter widget's current x and y coordinates?
- How to change the background color using jQuery?
- How to change the text color of Menu item in Android?
- How to change the background color of the font in PowerShell?
- How to reset the background color of a Python Tkinter button?
Advertisements