self.button = gtk.Button(stock=gtk.STOCK_DELETE)

Only Shows: Delete

share|improve this question
    
This answer might help you: stackoverflow.com/questions/1734914/… – Trent Feb 3 '10 at 0:00
up vote 9 down vote accepted

This is a recent change in GTK - the developers wanted icons not to appear on buttons. On Linux, this can be changed by editing the gconf key

/desktop/gnome/interface/buttons_have_icons

On windows, I think (I haven't actually tried this) that you need to set a value in your gtkrc file (for me it's in C:\Program Files\Gtk+\etc\gtkrc) and use a theme that supports icons (I think the default one doesn't).

You can also add gtk-button-images = 1 to your ~/.gtkrc-2.0 file after setting the theme which may over ride the option from gconf.

EDIT in answer to your comment:

Just like this answer, but in Python: In Gtk, how do I make a Button with just a stock icon?

For python, it's just

image = gtk.Image()
#  (from http://www.pygtk.org/docs/pygtk/gtk-stock-items.html)
image.set_from_stock(gtk.STOCK_**)
button = gtk.Button()
button.set_image(image)
button.set_label("")
share|improve this answer
    
Thanks for the prompt answer. Do you happen to know how to remove the text portion of icons from buttons? – aberkowitz Feb 3 '10 at 1:21
    
I answered your comment in the edit - it's basically like the question Trent posted in the comment to your original question. – Daniel G Feb 4 '10 at 22:08
    
@DanielG What is the value you need to change in Windows? – techno Dec 11 '13 at 12:29

in Gtk3 gtk.STOCK method has been deprecated from v3.10.

Deprecated since version 3.10: Use Gtk.Button.new_with_label () instead.

In the case it doesn't help since it points to the custom label solution (new_with_label) If you want to use STOCK stuff you still can do so with new methods Gtk.Button.new_from_icon_name(icon_name, size) and Gtk.Button.new_with_mnemonic(label) which will create new buttons with stock icon and label respectively.

Example new button with a "stock" icon:

button = Gtk.Button.new_from_icon_name ("edit-paste", Gtk.IconSize.SMALL_TOOLBAR)

Example new button with a "stock" label:

button = Gtk.Button.new_with_mnemonic("_Open")

NOTE: on serious code creating a constant variable instead of using the string straight is a better option :)

References:

share|improve this answer

If you work with pygobject, the new syntax is:

image.set_from_stock(gtk.STOCK_**, Gtk.IconSize.BUTTON)
share|improve this answer
    
I had to use gtk.ICON_SIZE_BUTTON – jsj Aug 29 '12 at 10:59

You can show explicitly the button image, justly, Gtk+ developers do not recommend doing this because it's overrides the Gtk+ user configuration.

So...

button.get_image().show()
share|improve this answer

The Python equivalent for setting the property without having to change any system config files is:

settings = gtk.settings_get_default()
settings.props.gtk_button_images = True

This should follow a call to window.show() and, obviously, precede the gtk.main() loop.

share|improve this answer
1  
If anyone's looking to do this in C, GtkSettings *settings = gtk_settings_get_default(); g_object_set(settings, "gtk-button-images", TRUE, NULL); is the equivalent procedure. – Fraxtil Jul 23 '14 at 23:49

I had the same issue in GTKmm on Windows. The "MS-Windows" theme disables images on stock buttons and the theme has priority over settings in gtkrc (so putting gtk-button-images = true in gtkrc didn't help). What I did is to modify the GTK settings runtime, and the images appeared as expected. :) Here's the code in C++:


Glib::RefPtr<Gtk::Settings> settings = Gtk::Settings::get_default();
/* force using icons on stock buttons: */
settings->property_gtk_button_images() = true; 

It should be placed after the first window is constructed.

share|improve this answer

I had to do this to get it to work from Python without changing my config file. When I called set_image(), no image was being displayed.

image = gtk.Image()
image.set_from_stock(gtk.STOCK_**, gtk.ICON_SIZE_BUTTON)
button = gtk.Button()
button.add(image)
button.show()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.