I have created a Menu:
self.commandMenu = Menu(menubar, tearoff = 0)
self.commandMenu.add_command(label = "Rename", accelerator = "Ctrl+R", command = self.onRename, state = "disabled")
self.commandMenu.add_command(label = "Edit module name", command = self.onEditModuleName, state = "disabled")
self.commandMenu.add_command(label = "Create instance", command = self.onCreateInstance, state = "disabled")
self.commandMenu.add_command(label = "Delete instance", command = self.onDeleteInstance, state = "disabled")
I plan on configuring all of its items sometime later, but the following code configures 1 item at a time:
self.commandMenu.entryconfig(1, state = "normal")
Is there a way to obtain the total amount of menu items, or configure all items at once?
You can use self.commandMenu.index("end") to get the index of the last item in the menu. You can then iterate over the items to configure them all:
last = self.commandMenu.index("end")
for i in range(last+1):
self.commandMenu.entryconfigure(i, state="normal")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With