0

I add a button to HBox, with expand equal to False, but I want the button to have more spacing between its label and border. I assume it is "inner-border" property, but it is read-only. How can I set it to e.g. 4px?

CDspace
  • 2,639
  • 18
  • 30
  • 36
Marin
  • 1,311
  • 16
  • 35

4 Answers4

2

gtk.Label is a subclass of gtk.Misc which has the method set_padding. If you get the label out of the gtk.Button then you can just call set_padding on it.

You could do something like:

label = gtk.Label("Hello World")
button = gtk.Button()

/* Add 10 pixels border around the label */
label.set_padding(10, 10)

/* Add the label to the button */
button.add(label)

/* Show the label as the button will assume it is already shown */
label.show()
zondo
  • 19,901
  • 8
  • 44
  • 83
iain
  • 5,660
  • 1
  • 30
  • 51
  • Thanks, that's it! :) py code, if anyone needs it: some_btn.get_children()[0].set_padding(10,10) – Marin Sep 23 '11 at 08:50
1

Wrong answer:

What you're looking for is called "padding". When you add your button to the container, for example by calling gtk.Box.pack_start, just set the padding parameter to a positive integer.

Update:

Seems I misread the question. In that case, my guess is that you're supposed to use gtk_widget_modify_style, as inner-border is a style property. You'll first get the style modifier you need by calling gtk_widget_get_modifier_style. You'll then be able to modify the style only for that button using the ressource styles matching rules.

liberforce
  • 11,189
  • 37
  • 48
0

you can use "inner-border" style property of gtk button.

here, small code snippets

In gtkrc file:

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  class "GtkButton" style "button_style"

In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

[Edit]

In gtkrc file:

  style "button_style"
  {
   GtkButton::inner-border = {10,10,10,10}
  }
  widget "*.StyleButton" style "button_style" # apply style for specific name of widget


In .py file:

  gtk.rc_parse(rc_file_path + rc_file)

  #set name of button
  self.style_button.set_name('StyleButton')

hope, it would be helpful.

Yajushi
  • 1,175
  • 2
  • 9
  • 24
-1

I sometimes just add spaces in the label !

gtk.Button("  Label  ")

to get some spacing.

Hope this could help you.

Louis
  • 2,854
  • 2
  • 19
  • 24
  • heh, it works, but it isn't really a "legit" way. Isn't there a proper way to achieve this? – Marin Sep 22 '11 at 09:02