[Tkinter-discuss] Get menu index from label

Alan Gauld alan.gauld at yahoo.co.uk
Fri Apr 14 14:11:21 EDT 2023


I'm trying to extract a menu entry's index given the
entry label.
ie for the typical File... menu, with entries of:
New, Open, Save, Save As, etc...

How do I get the index of the entry labelled
"Save As", given I have a reference to the
containing menu object?

Once I have an index I can do various things to the
entry but there seems to be no way to access the entry
without an index and no way to get the index (other
than counting manually, which is no good where the
menu content changes dynamically) based on the label.

The top level requirement is to toggle the label
between two values when certain state changes occur.
(I could use a checkbox menuitem but those are not
common UI elements and might confuse some users.)

[ Another solution would be to get the list of items
in the menu, but I can't see how to do that either
(which seems odd!) With that list I could loop to
find the item/index. ]

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tkinter-discuss mailing list