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?
4 Answers
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()
-
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
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.

- 11,189
- 37
- 48
-
-
I've fixed my answer (you'll need to adapt from C to Python however) , please reconsider it... – liberforce Sep 27 '11 at 15:11
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.

- 1,175
- 2
- 9
- 24
-
1this would change all of the buttons, I only need to change this one button. – Marin Sep 22 '11 at 09:02
I sometimes just add spaces in the label !
gtk.Button(" Label ")
to get some spacing.
Hope this could help you.

- 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