Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygtk: Change a widget's border color

I have looked everywhere but couldn't seem to find a way to change the color of the border. For example I need a button like this:

gb = gtk.Button("Hi")
gb.set_border_width(50)

Now I wish to color the border red (this is a non-existent call):

gb.set_border_color('red')

I tried gb.modify_bg(...) but it only changes the background of the button, not the BORDER surrounding it. The closet thing I can get is adding this GtkButton to a GtkFrame, and use the frame's shadow color. However the shadow box's width is fixed - it's a thin line way below my desired thickness.

It's intuitive to me that if you can change the width of a border, you should be able to set more styles on it. I am open to other ways to achieve the same thick-colored-border effect, such as laying the button on top of some big, colored background?

Thanks for any help here.

like image 209
Eric Chen Avatar asked Apr 28 '11 00:04

Eric Chen


1 Answers

AFAIR, gtk.Button border handling is engine-dependent. If you don't want to mess with styles, you could create gtk.EventBox, set its background color, pack the button, and then set the amount of empty space around the button to desired value:

button = gtk.Button("Click me")
button.set_border_width(50)
eb = gtk.EventBox()
eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("pink"))
eb.add(button)
like image 91
barti_ddu Avatar answered Nov 15 '22 10:11

barti_ddu