7

I'm new to GTK3 (I prefer wxWidgets), and I can't load a stock icon to a gtk.button...

This is my attempt:

image = Gtk.Image()
pb = Pixbuf.new_from_stock(Gtk.STOCK_OPEN)

self.browse_button = Gtk.Button(label="")
self.browse_button.set_from_pixbuf(pb)

This is how it is done on wxWidgets (much more simpler):

self.browse_button = wx.BitmapButton( self, wx.ID_ANY, wx.ArtProvider.GetBitmap( wx.ART_FILE_OPEN, wx.ART_MENU ), wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW )

any help?

Hairo
  • 2,062
  • 5
  • 27
  • 33

2 Answers2

6

Try:

image = Gtk.Image(stock=Gtk.STOCK_OPEN)
self.browse_button = Gtk.Button(label="Some Label", image=image)

See the documentation.

ptomato
  • 56,175
  • 13
  • 112
  • 165
4

Like Ptomato did, but with no label and using one line :

self.btnOpen = Gtk.Button(None,image=Gtk.Image(stock=Gtk.STOCK_OPEN))
Jean Coiron
  • 632
  • 8
  • 24