Hello, im currently working on a program and im trying to create a cascade, This cascade code works by itself but i want to implement def hello and def toggle into def __init__(self, master=None), at the moment im getting and error "UnboundLocalError: local variable 'submenu' referenced before assignment" does anyone know how i could fix this? I would like the code to stay inside the def __init__ because i will be adding other functions into this.
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
self.master = master=None
self.menubar = Menu(self.master)
Frame.__init__(self)
self.grid()
self.toggle()
self.hello()
def hello(self):
print "hello !"
def toggle(self):
if submenu.entrycget(0,"state")=="normal":
submenu.entryconfig(0,state=DISABLED)
submenu.entryconfig(1,label="Speak please")
else:
submenu.entryconfig(0,state=NORMAL)
submenu.entryconfig(1,label="Quiet please")
menubar = Menu(self)
submenu=Menu(menubar,tearoff=0)
submenu2=Menu(submenu,tearoff=0)
submenu2.add_command(label="hello", command=meat)
# this cascade will have index 0 in submenu
submenu.add_cascade(label="Say",menu=submenu2,state=DISABLED)
# these commands will have index 1 and 2
submenu.add_command(label="Speak please",command=toggle)
submenu.add_command(label="Exit", command=self.quit)
menubar.add_cascade(label="Test",menu=submenu)
## display the menu
self.config(menu=menubar)
self.mainloop()
app = Application()
app.master.title("Major Project Sample Screen")
app.mainloop()