
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Set Background Color of TTK Combobox in Tkinter
Tkinter supports ttk widget which is used to change the style and properties of any widget in a tkinter application. We can set the background color, foreground color, and other attributes of the Combobox widget by visiting the configure function in ttk and passing 'TCombobox' as the first parameter.
Example
In this example, we will set the background color of the Combobox widget by defining its values in the ttk widget.
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Define the style for combobox widget style= ttk.Style() style.theme_use('clam') style.configure("TCombobox", fieldbackground= "orange", background= "white") # Add a label widget label=ttk.Label(win, text= "Select a Car Model", font= ('Aerial 11')) label.pack(pady=30) # Add a Combobox widget cb= ttk.Combobox(win, width= 25, values=["Honda", "Hyundai", "Wolkswagon", "Tata", "Renault", "Ford", "Chrevolet", "Suzuki","BMW", "Mercedes"]) cb.pack() win.mainloop()
Output
Running the above code will open a window that will have a combobox widget to select an option from the list.
Advertisements