Im working on this bit of code below, The only thing im worried about editing atm is the self.toggle() and self.hello(). Im currently getting this error TclError: unknown option "-menu" from this line of code self.config(menu=menubar), does anyone know how i could fix this problem??
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
self.master = master
self.menubar = Menu(self.master)
Frame.__init__(self)
self.grid()
self.createQuit()
self.createHelp()
self.createRegister()
self.createHeader()
self.createSpace()
self.createMenu()
self.createOrder()
self.toggle()
self.hello()
def createHeader(self):
top=self.winfo_toplevel()
top.rowconfigure(0,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.heading = Label ( self, text="Major Project Draft",relief=FLAT, font=('Arial', 30))
self.heading.grid(row=0, column=0)
def createSpace(self):
top=self.winfo_toplevel()
top.rowconfigure(1,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.columnconfigure(0, weight=1)
self.heading = Label ( self, text="",relief=FLAT, font=('Arial', 20))
self.heading.grid(row=1, column=0)
def createHelp(self):
top=self.winfo_toplevel()
top.rowconfigure(2,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(2, weight=1)
self.columnconfigure(0, weight=1)
self.button = Button ( self, text="HELP",relief=FLAT, font=('Arial', 20))
self.button.grid(row=2, column=0)
def createRegister(self):
top=self.winfo_toplevel()
top.rowconfigure(3,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(3, weight=1)
self.columnconfigure(0, weight=1)
self.button = Button ( self, text="REGISTER AS MEMBER",relief=FLAT, font=('Arial', 20))
self.button.grid(row=3, column=0)
def createOrder(self):
top=self.winfo_toplevel()
top.rowconfigure(5,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(5, weight=1)
self.columnconfigure(0, weight=1)
self.button = Button ( self, text="ORDER FOOD",relief=FLAT, font=('Arial', 20,))
self.button.grid(row=5, column=0)
def createQuit(self):
top=self.winfo_toplevel()
top.rowconfigure(7,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(7, weight=1)
self.columnconfigure(0, weight=1)
self.quit = Button ( self, text="QUIT", command=self.quit,relief=FLAT, font=('Arial', 20))
self.quit.grid(row=7, column=0)
def createMenu(self):
self.mb = Menubutton ( self, text='FOOD MENU',
relief=FLAT, font=('Arial', 20))
top=self.winfo_toplevel()
top.rowconfigure(6,weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(6, weight=1)
self.columnconfigure(0, weight=1)
self.mb.grid(row=6, column=0)
self.mb.menu = Menu (self.mb, tearoff=0)
self.mb['menu'] = self.mb.menu
Meat = self.mb.menu.add_cascade ( label='Meat')
self.menubar = Menu
self.casmenu = Menu
self.casmenu.choices = Menu
self.casmenu.choices.wierdones = Menu(self)
self.casmenu.choices.wierdones.add_cascade(label='Steak')
self.casmenu.choices.wierdones.add_cascade(label='Garlic Prawns')
Seafood = self.mb.menu.add_cascade ( label='Seafood')
Pasta = self.mb.menu.add_cascade ( label='Pasta')
Vegitarian = self.mb.menu.add_cascade ( label='Vegitarian')
Desserts = self.mb.menu.add_cascade ( label='Desserts')
Beverages = self.mb.menu.add_cascade ( label='Beverages')
menubar = Menu(self)
submenu=Menu(menubar,tearoff=0)
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")
submenu2=Menu(submenu,tearoff=0)
submenu2.add_command(label="hello", command=hello)
# 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("Sample Screen")
app.mainloop()