1
votes

I can't figure out or find how to disable a tkinter OptionsMenu. I have 3 optionsmenu's in my GUI and want to disable them when a button is clicked

self.menu = OptionMenu(self, var, *items)
btn = Button(self, text="disable", command = self.disable)
btn,pack()

self.disable(self):
    //Disable menu here...

Is there a way to just call a built in function for OptionMenu and disable it? Or do I have to disable every option in the menu? (Which i also can't figure out)

BTW: I used the menu.pack() for a separate Topleve() window that pops up, but I started off with the grid() system in my main Tk window, used by menu.grid(row=0,column=0)

EDIT: So I forgot to mention that I have multiple OptionMenus being generated by a constructor method. This is what I tried doing and didn't work:

makeMenu():
    menu = OptionMenu(self, var, *items)
    ....//whole bunch of menu settings
    return menu

menu1 = makeMenu()
all_menus.append(menu)

Now the reason this didn't work is because I had to append it after creation. I don't know why the settings don't carry over, but what I had to do is this: makeMenu(): menu = OptionMenu(self, var, *items) ....//whole bunch of menu settings return menu

makeMenu():
    menu = OptionMenu(self, var, *items)
    ....//whole bunch of menu settings
    all_menus.append(menu)

makeMenu()

And with this change, I can use this to disable menus later on:

for menu in all_menus:
   menu.config(state=DISABLED)
1
Close. But this has to do with OptionMenu's which work a little differently. I used that question for my input entries. It works! But unfortunately it doesn't with OptionMenu's. Thanks for the heads up though! - E. Oregel
I tested it and it does work on OptionMenus. Admittedly there's no optical clue, but if you click a disabled OptionMenu nothing happens. - Aran-Fey
Ok. I'll give it another shot. If it still doesn't work, i'll post my attempt as an edit above. - E. Oregel
If that wasn't clear, the "parent widget" isn't the OptionMenu. An OptionMenu has no child widgets. I was thinking of your 3 OptionMenus as the children of some container. - Aran-Fey

1 Answers

7
votes

Like with any other widget, you use the configure method to set the state to "disabled":

self.menu.configure(state="disabled")

The above will work for both the tkinter and ttk OptionMenu widgets.