开发者

How can a custom icon be used in an image menu item?

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜