[pygtk] Using an RC file to set the background colout of Gtk.Button

Martin A Conaghan mac34 at st-andrews.ac.uk
Thu Jan 24 02:21:09 WST 2008


I am trying to use an RC file to set the background colour of a button. I a=
m able to change the colour of the font usinf the RC file, but not the back=
ground colour or font. I am able to change the background of the window. Th=
e RC file is;

style "window"

{

font =3D "-Adobe-Times-Bold-I-Normal--14-100-100-100-P-77-ISO8859-1"

# Yellow background

bg[NORMAL] =3D {1.0, 1.0, 0}

}


style "button"

{

font =3D "-Adobe-Times-Bold-I-Normal--14-100-100-100-P-77-ISO8859-1"


# Change font colour, WORKS

fg[PRELIGHT] =3D { 0, 0, 1.0 }

fg[ACTIVE] =3D { 0, 1.0, 0 }

fg[NORMAL] =3D { 1.0, 0, 0 }

fg[INSENSITIVE] =3D { 1.0, 1.0, 0 }

#Try to change background colour, DOES NOT WORK

bg[PRELIGHT] =3D { 0, 0, 1.0 }

bg[ACTIVE] =3D { 0, 1.0, 0 } =


bg[INSENSITIVE] =3D { 1.0, 1.0, 0 }

bg[NORMAL] =3D { 0, 1.0, 1.0 }





base[PRELIGHT] =3D { 0, 0, 1.0 }

base[ACTIVE] =3D { 0, 0, 1.0 }

base[NORMAL] =3D{ 0, 0, 1.0 }

base[INSENSITIVE] =3D { 0, 0, 1.0 }


}


widget_class "GtkWindow" style "window"

widget_class "*GtkButton*" style "button"



I am able to set the colour of the button by editing the style in this meth=
od;

def setWidgetColour(widget, colour_string):

""" Takes a widget and sets the colour. """

r, g, b =3D colourToRGB16Bit(colour_string)

color =3D widget.get_colormap().alloc_color(r, g, b)


s =3D widget.get_style().copy()

for i in range(5):

s.fg[i] =3D color

s.bg[i] =3D color

s.base[i] =3D color

widget.set_style(s) =


The problem is that when I use this method I lose the rounded corners which=
 I want to keep. Plus I'd rather use the RC files for ease of modification.

Having searched around for similar problems some people say that you need t=
o set the colour of the label, but then some people say that the label is i=
nvisible. Others say you need to add the Button to a gtk.EventBox, so I'm a=
 little confused

I am using the most recent version of PyGTK (as of yesterday) with Python2.=
5. =


Any help would be greatly appreciated- Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080123/50167069/at=
tachment-0001.htm


More information about the pygtk mailing list