On 14/04/2023 23:35, Bryan Oakley wrote: > You can use the label string as the index. Or more accurately, a pattern > that matches an element. Once tkinter finds an item that matches the > pattern, that item will be used. For example, "Save*" might match both > "Save" and "Save As...", but whichever one comes first in the menu is > the one that will be used. > > file_menu.entryconfig("Save*", state="disabled")
I knew there must be a simple way, it seemed such an obvious thing to want to do. But I couldn't find anything about using the label as an index in any of my Tk/Tkinter books (and I have 6 covering Tkinter and 2 covering Tcl/Tk!) I got numerical indices and symbolic ones like "first" and "last" but no mention of using the label string (and especially not a partial string pattern). > If you want to get the numerical index of an item, you can use the index > method. > > index = file_menu.index("Save As") And this makes much more sense now, I couldn't fathom out what menu.index(index) meant! Thanks so much. -- 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 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss