can I change the color of python ttk combobox unde

2019-07-17 08:23发布

I got working code under Linux to change the appearance of a TCombobox of Ttk under python 2.7. If I run the code under windows, it wont work. Im aware, that colors and also attributes of the ttk widgets are platform-dependant. Still I cannot figure out how to change the color of either the textarea or the downarrow of the combobox under windows. The code, which is working under linux is like that:

self = Tkinter.Canvas
style = ttk.Style()
style.configure('Yellow.TCombobox',background="yellow")
combo = ttk.Combobox(self,width=12,font=("Arial",8),style="Yellow.TCombobox")

I tried to find out about which attributes the TCombobox has got under windows by:

    print style.layout("TCombobox")
    style.configure("Yellow.TCombobox",fieldbackground="yellow")
    print style.lookup("Yellow.TCombobox", 'fieldbackground')

My print output is the following:

[('Combobox.field', {'children': [('Combobox.downarrow', {'side':
 'right', 'sticky': 'ns'}), ('Combobox.padding', {'children': 
[('Combobox.focus', {'children':
[('Combobox.textarea', {'sticky': 'nswe'})], 'expand': '1', 'sticky':     
'nswe'})], 'expand': '1', 'sticky': 'nswe'})], 'sticky': 'nswe'})]

yellow

However, although the attribute fieldbackground is changed to yellow, the appearance of the combobox does not change. So, how do I change colors?

Thanks in Advance!

1条回答
做个烂人
2楼-- · 2019-07-17 08:33

Might be a bit late for Sammy but for others I got mine working by putting

style.theme_use("alt")

after the style is defined and the combobox started working as intended but does alter the look and feel on the widget so might not be ideal solution.

查看更多
登录 后发表回答