我可以更改 Windows 下 python ttk 组合框的颜色吗? [英] can I change the color of python ttk combobox under windows?

查看:21
本文介绍了我可以更改 Windows 下 python ttk 组合框的颜色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 下得到了工作代码来改变 python 2.7 下 Ttk 的 TCombobox 的外观.如果我在 Windows 下运行代码,它将无法工作.我知道,ttk 小部件的颜色和属性取决于平台.我仍然无法弄清楚如何更改 windows 下组合框的 textarea 或 downarrow 的颜色.在linux下运行的代码是这样的:

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")

我试图通过以下方式找出 TCombobox 在 windows 下具有哪些属性:

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')

我的打印输出如下:

[('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

不过,虽然属性fieldbackground变成了黄色,但是combobox的外观并没有改变.那么,如何更改颜色?

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

提前致谢!

推荐答案

对于 Sammy 来说可能有点晚了,但对于其他人来说,我通过放置获得了我的工作

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.

这篇关于我可以更改 Windows 下 python ttk 组合框的颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆