获取当前gtk风格的颜色

我使用PyGTK,我想获得一个小部件的颜色(例如bg颜色),我运行这样的代码:

gdkColorToRgb = lambda gc: (gc.red//257, gc.green//257, gc.blue//257)
widget = gtk.HBox() ## for example
style = widget.get_style()
for i in range(5):
    print i, gdkColorToRgb(style.bg[i])

但它并没有给我目前的gtk主题(风格)的颜色。 它似乎是默认的gtk主题(我目前的主题是黑暗的,而这段代码给出了浅色)我使用ArchLinux和PyGTK 2.24.0(GTK 2.24.5)


我偶然发现了同样的问题,看到了你的问题,并找到了一个解决方案:你必须等到widget实现,例如这样:

def print_style(widget):
    style = widget.get_style()
    for i in range(5):
        print i, gdkColorToRgb(style.bg[i])
gdkColorToRgb = lambda gc: (gc.red//257, gc.green//257, gc.blue//257)
widget = gtk.HBox() ## for example
widget.connect('realize', print_style)
链接地址: http://www.djcxy.com/p/37897.html

上一篇: Get colors of current gtk style

下一篇: Database: Splitting Tables