Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - gtk3 add stock icons to Gtk.Buttons

Tags:

python

icons

gtk3

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?

like image 588
Hairo Avatar asked Aug 27 '12 00:08

Hairo


2 Answers

Try:

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

See the documentation.

like image 162
ptomato Avatar answered Nov 03 '22 01:11

ptomato


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

self.btnOpen = Gtk.Button(None,image=Gtk.Image(stock=Gtk.STOCK_OPEN))
like image 20
Jean Coiron Avatar answered Nov 03 '22 02:11

Jean Coiron