Get the colors of the current gtk style

I use PyGTK, and I want to get the colors of the widget (for example, the color bg), I ran this code:

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

But this does not give color to my current gtk (style) theme. It seems that for the default gtk theme (my current theme is dark while this code gives light colors) I am using ArchLinux and PyGTK 2.24.0 (GTK 2.24.5)

+1
source share
1 answer

I just stumbled upon the same problem, saw your question and found a solution: you need to wait until the widget is implemented, for example. eg:

 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) 
+1
source

All Articles