How can I change the display text of a MenuItem in Gtk2?
Question
I need to change the display text of a MenuItem. Is there any way of doing this without removing the MenuItem and then adding another one with a different text?
Solution
It somewhat depends how you created the menu item, since a MenuItem is a container that can contain anything. If you created it like:
menuitem = gtk.MenuItem('This is the label')
Then you can access the label widget in the menu item with:
label = menuitem.child
And can then treat that as a normal label:
label.set_text('This is the new label')
However, unless you made the menu item yourself, you can't guarantee that the child widget will be a label like this, so you should take some care.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow