I have a GUI that I created in Tkinter which has a menu. I want a button that when clicked toggles the menu being enabled / disabled.
So I wrote the following minimal example (based off of https://mail.python.org/pipermail/tkinter-discuss/2004-September/000204.html) which works fine on my Windows 7 and Ubuntu 14.04 machines (using Python 2.7.6 and Tkinter Revision 81008). However when I tried the same code (again under Python 2.7.6 and Tkinter Revision 81008) on Mac 10.9 the menu would disable but would not reenable. Additionally, the example below also prints out what state it thinks the menu has (using entrycget) and it would print out that it thought that the menu was alternating between enabled and disabled.
Can anyone reproduce this behaviour? Is this a known bug? Or is there an alternate way to enable / disable menus on Mac
from Tkinter import *
root=Tk()
def hello():
print "hello !"
menubar = Menu(root)
submenu = Menu(menubar, tearoff=0)
submenu.add_command(label="Hello", command=hello)
menubar.add_cascade(label='test', menu=submenu)
root.config(menu=menubar)
def toggle():
print('I think the menu bar is %s' % menubar.entrycget(0,"state"))
if menubar.entrycget('test', "state")=="normal":
print('disabling')
menubar.entryconfig('test', state=DISABLED)
print('disbled')
else:
print('enabling')
menubar.entryconfig('test', state=NORMAL)
print('done')
b = Button(root, text='Toggle', command=toggle)
b.pack()
root.mainloop()