开发者

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

开发者 https://www.devze.com 2023-01-27 12:19 出处:网络
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?

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

精彩评论

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