SOHAM DAS BISWAS.
SOHAM DAS BISWAS.

Reputation: 71

How to change the background color of combobox in tkinter?

I am trying to change the background color of combobox in tkinter to red. But I am unable to do so kindly help. This is my code '''

#code

style = ttk.Style()

style.map('TCombobox', fieldbackground=[('readonly','red')])
style.map('TCombobox', selectbackground=[('readonly', 'red')])
style.map('TCombobox', selectforeground=[('readonly', 'white')])



n= tk.StringVar(value=download_choices[0])
n.set(download_choices[0])
youtubeChoicesLabel = ttk.Combobox(root, font=font, justify='center', textvariable=n, values=download_choices)
youtubeChoicesLabel["state"] = "readonly"
youtubeChoicesLabel.bind('<<ComboboxSelected>>')
youtubeChoicesLabel.current(0)
# youtubeChoicesLabel["selectbackground"] = '#ff0000'
# youtubeChoicesLabel["foreground"] = '#000000'
youtubeChoicesLabel.pack(side=TOP, pady=20)

'''

Upvotes: 0

Views: 1588

Answers (1)

ahmetknk
ahmetknk

Reputation: 348

The problem lies with the theme you are using. Some themes just will not let you change certain features. For instance, if you are using "vista" theme you can not change the background color of buttons or comboboxes.

You need to change your theme to one that allows you to change features like background colors of buttons or comboboxes. You can change your theme as shown:

style.theme_use("default")

You do not have to necessarily use "default" theme, you just need to use a theme which allows you to change background color of combobox. I used "default" because I know it lets you change the background color.

Upvotes: 1

Related Questions