How to change background color in ttk.Combobox's listview? How to change background color in ttk.Combobox's listview? tkinter tkinter

How to change background color in ttk.Combobox's listview?


Found it! the way to change the BG of the listview of the combobox is:

import ttkimport Tkinterroot = Tkinter.Tk()root.option_add("*TCombobox*Listbox*Background", 'green')combo = ttk.Combobox().pack()root.mainloop()


Your answer to your own question helped me solve mine. So, I figured I'd help you and others by contributing a bit further :)

Seeing your code in the question leads me to believe you want to change more than just the background color of the Listbox. I've played around with this a bit, and I'm sure there are some other options available, but this allows you to update the Combobox entry field background and text colors, as well as the Listbox field background and text colors.

I've included an example picture of a Combobox/Listbox from an app I've written using the code below (adapted for this response).

Hope this helps you and any future travelers!

import tkinter as tkfrom tkinter import ttk# variables created for colorsebg = '#404040'fg = '#FFFFFF'root = tk.Tk()style = ttk.Style()# Note the code line below.# Be sure to include this or style.map() won't function as expected.style.theme_use('alt')# the following alters the Listboxroot.option_add('*TCombobox*Listbox*Background', ebg)root.option_add('*TCombobox*Listbox*Foreground', fg)root.option_add('*TCombobox*Listbox*selectBackground', fg)root.option_add('*TCombobox*Listbox*selectForeground', ebg)# the following alters the Combobox entry fieldstyle.map('TCombobox', fieldbackground=[('readonly', ebg)])style.map('TCombobox', selectbackground=[('readonly', ebg)])style.map('TCombobox', selectforeground=[('readonly', fg)])style.map('TCombobox', background=[('readonly', ebg)])style.map('TCombobox', foreground=[('readonly', fg)])

Combobox and Listbox color example