[pygtk] modify gtk button color

Tony Nelson tonynelson at georgeanelson.com
Tue Jan 31 13:26:18 WST 2006

At 12:03 PM +1000 1/31/06, vector wrote:
>Im sure this has been dealt with b4 but I have searched and tried
>various things and Im just not "getting" it.
> From what i read I think the labels background in the button is what i
>want to set. Ergo i need to find the "child"!?.And this is where i fail.
># set up button
>        button = gtk.Button("hello")
>#modify its color
>        child_label=gtk_bin_get_child (GTK_BIN (button))
>child_label.modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse("light pink"))
>NameError: global name 'gtk_bin_get_child' is not defined
>Im possibly not even close?

First, you are using the C syntax, not the Python syntax, which is

Second, experimenting, I see that (contrary to the docs) setting the
background of a Button does work:

    button.modify_bg(gtk.STATE_xxx, gtk.gdk.Color(r,g,b))

Where xxx is NORMAL for the resting state, PREFLIGHT for mouse hovering,
and ACTIVE for pressed.  The colors don't overlap exactly, so all colors
should be related.  Also, people will complain when you violate the theme
colors when you change them in any way.

There's also the Widget's Style object, normally set up by the theme.
(button.get_style(), etc.).
TonyN.:'                       <mailto:tonynelson at georgeanelson.com>
      '                              <http://www.georgeanelson.com/>

More information about the pygtk mailing list