6

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.

Eric Chen
  • 3,562
  • 7
  • 39
  • 58
  • 1
    I think thats the job of theme, not the code. Since the user may use a theme that the button's border is a gradient (from one color to another), and you will override that part of button (border) with one color, and it may make it ugly! I don't think this is a good idea, event if possible. – saeedgnu Apr 28 '11 at 05:02
  • Could you provide an example theme that changes border color? I couldn't find the relevant gtkrc styles. Thanks. – Eric Chen Apr 28 '11 at 20:47
  • @ilius: Yes, this is a job of the theme, but in some situations you may want to explicitly define it. – Alba Mendez Sep 04 '11 at 11:36

1 Answers1

7

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)
barti_ddu
  • 10,179
  • 1
  • 45
  • 53
  • This does solve my original problem! I am curious how I would mess with styles to actually color the button border. Do you have a working example style? Thanks! – Eric Chen Apr 28 '11 at 20:59
  • @e_x_p: no, i've stopped overriding theme styles a long ago :) You may want to check http://faq.pygtk.org section "4. Themes, fonts and styles", it has few examples which may give you some insight. – barti_ddu Apr 29 '11 at 15:02