I can create menu items with icons:
new = gtk.ImageMenuItem(gtk.STOCK_NEW, 'New')
but how can I use a custom icon -开发者_Python百科 from a file?
http://library.gnome.org/devel/pygtk/stable/class-gtkimagemenuitem.html#method-gtkimagemenuitem--set-image
img = gtk.Image()
img.set_from_file(filename)
new = gtk.ImageMenuItem(gtk.STOCK_NEW, 'New')
new.set_image(img)
For me the following code worked:
img = gtk.Image()
img.set_from_stock(gtk.STOCK_NEW, 1)
item = gtk.ImageMenuItem('New')
item.set_image(img)
menu.append(item)
精彩评论