How to make tkinter combobox dark themed? I already tried a bit, but nothing really looked good. Im trying to do something like this:
If someone could help me to build something near this, I would appreciate it a lot!
I experimented a bit with these two codes, but it wasn't really what I looked for:
style= ttk.Style()
style.theme_use('clam')
style.configure("TCombobox", fieldbackground= "orange", background= "white")
combostyle = ttk.Style()
combostyle.theme_create('combostyle', parent='alt',
settings = {'TCombobox':
{'configure':
{'selectbackground': 'blue',
'fieldbackground': 'red',
'background': 'green'
}}}
)
combostyle.theme_use('combostyle')
You're close, but missing two lines.
style.configure("TCombobox",fieldbackground='black', background= "white",foreground='white') # changes colour of combobox itself (foreground is the text colour, background is the background colour of the arrow to drop down)
win.option_add("*TCombobox*Listbox*Background", 'black') # changes background of drop down menu of combobox
win.option_add('*TCombobox*Listbox*Foreground', 'white') # changes colour of text of options in combobox
# 'win' is the name of your window
EDIT (requested full code that I used):
# 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='black', background= "white",foreground='white')
win.option_add("*TCombobox*Listbox*Background", 'black')
win.option_add('*TCombobox*Listbox*Foreground', '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()