Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu total index counts, length of menu items

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?

like image 851
James the Great Avatar asked Feb 03 '26 19:02

James the Great


1 Answers

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")
like image 149
Bryan Oakley Avatar answered Feb 05 '26 07:02

Bryan Oakley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!