Setting custom label for ImageMenuItem widget with stock icon in pygtk

Advertisements

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….> ‘)


June 11th, 2009 Written by digitalcoconut    

Free subscription: Subscribe RSS feed or get daily tips in your email
* Click confirmation link sent in email * Don't see the email? check spam folder

  Facebook 


Liked it? Share...   Digg It!   Submit to Del.icio.us   Submit to Reddit   Stumble   Submit to Identica   Slashdot It   Send to a friend via email


blog comments powered by Disqus