Setting custom label for ImageMenuItem widget with stock icon in pygtk

python-logoYou may have wanted to change the label contents of the stock item which you attached into the ImageMenuItem widget, but couldn’t find an easy way out to do it. We here present to you in simple steps a way to achieve this and set the label contents to anything you desire.

For example, you may wish to use the Help Icon with label content as ‘Contents’ rather than the default ‘Help’.

menu=gtk.Menu()
item=gtk.ImageMenuItem(gtk.STOCK_HELP)

The above lines creates for you a conventional Help menu item with label content ‘Help”.

item.get_children()[0].set_label(‘Contents’)
menu.append(item)
item.connect(“activate”, method)
item.show()

These above lines replace the word ‘Help’ with ‘Contents’. You can use it with any stock icons and can set the label contents to anything you desire by altering :

item.get_children()[0].set_label(‘<….Put anything you wish….> ‘)

If this sounds like your situation, let's talk

No pitch decks. No sales process. Just a conversation about what you're dealing with and whether I can help.

Book a 30-minute call →