0

Does anyone have any insight on this? I already made a style for the notebook background so i tried doing the same with the combo box brackground but it doesnt work. This is what i have.

combostyle = ttk.Style()

combostyle.theme_create('custom_style',
                   parent='alt',
                   settings={'TCombobox':
                             {'configure':
                              {'selectforeground': 'white',
                               'selectbackground': '#1a2228',
                               'fieldforeground': 'white',
                               'fieldbackground': '#1a2228',
                               'background': '#1a2228'
                               }
                              }
                             }
                   )
combostyle.theme_use('custom_style')

root.option_add('*TCombobox*Listbox*Background', '#1a2228')
root.option_add('*TCombobox*Listbox*Foreground', 'white')

SCREENSHOTS

enter image description here

enter image description here

2 Answers2

1

The code that you have posted is related to defining a new theme by configuring the ttk Combobox widget and using the same for your GUI.

I have posted the following code taking a similar approach to create a simple ttk Combobox with custom background and foreground color styles.

I have tested this with the default and alt parent themes.

The ttk combobox popdown listbox cannot be configured using ttk style nor via the widget configure command. The listbox can be configured using the option database. Read more about this here

I'm using Python 3.7, Tcl/Tk 8.6 on Windows.

import tkinter as tk
from tkinter import ttk

window = tk.Tk()

style = ttk.Style()
# creating a custom theme
style.theme_create('custom_style',
                   parent='alt',
                   settings={'TCombobox':
                             {'configure':
                              {'selectforeground': 'blue',
                               'selectbackground': 'yellow',
                               'fieldforeground': 'blue',
                               'fieldbackground': 'yellow',
                               'background':'yellow'
                               }
                              }
                             }
                   )
style.theme_use('custom_style')

# following are style option for the drop down combobox listbox
window.option_add('*TCombobox*Listbox*Background', 'blue')
window.option_add('*TCombobox*Listbox*Foreground', 'yellow')

values = ['CS', 'EC', 'ME']
select_branch = ttk.Combobox(window, values=values, width=15, state='readonly')
select_branch.grid(row=0, column=0, padx=10, pady=10)

window.mainloop()

Screenshots

s1

s2

s3

I hope this helps you!

Somraj Chowdhury
  • 983
  • 1
  • 6
  • 14
0

This topic has been discussed and solved in this Question here: Combobox Just have a look, it should clear any questions.

sxeros
  • 668
  • 6
  • 21