Home > database >  How to know all the disabled options in an Options Menu Tkinter Closed
How to know all the disabled options in an Options Menu Tkinter Closed

Time:04-07

I have disabled an option in an OptionMenu to fix something in the code where if I click on it just duplicates it, so I thought by disabling the option is an easy work around, but when the user may want to change to another option both the options are now disabled making the first one not usable again. I now need to return the option to normal. I thought of getting all the options which are disabled but couldn't figure out on how to do that. Sorry for the long para.

Any suggestions are useful.

CodePudding user response:

You might want to consider an object-oriented approach, defining for your object either a dict, list or some other array of settings, from which you can yourself easily fetch the status of any single control. Even if you don't want to do OOP, you should probably yourself save the current settings to an array.

CodePudding user response:

Assume optmenu is the instance of OptionMenu, the following code will return all the items that are disabled:

# optmenu is the instance of OptionMenu
menu = optmenu['menu']
items = []  # list to hold all disabled items
# go through all option items
for i in range(menu.index('end') 1):
    if menu.entrycget(i, 'state') == 'disabled':
        items.append(menu.entrycget(i, 'label'))
print(items)
  • Related