“重置”按钮不适用于该复选框,出现错误:AttributeError:'str'对象没有属性'END'。当我在某些框中写东西时,reset可以正常工作,但复选框未恢复原状,并且收到消息:AttributeError:'str'对象没有属性'END'
import random
import time;
import datetime
import tkinter.messagebox
from tkinter import *
root =Tk()
root.geometry("1350x750+0+0")
root.title("Restaurant Management System")
root.configure(background ="Cadet Blue")
Tops = Frame(root, bg="Cadet Blue", bd=20, pady=5, relief=RIDGE)
Tops.pack(side=TOP)
lblTitle = Label(Tops, font=('arial',60,'bold'), text="Restaurant Management System", bd=21, bg='Cadet Blue', fg='Cornsilk',justify=CENTER)
lblTitle.grid(row=0,column=0)
ReceiptCal_F = Frame(root, bg="Powder Blue", bd=10, relief=RIDGE)
ReceiptCal_F.pack(side=RIGHT)
Buttons_F=Frame(ReceiptCal_F, bg='Powder Blue', bd=3, relief=RIDGE)
Buttons_F.pack(side=BOTTOM)
Cal_F=Frame(ReceiptCal_F, bg='Powder Blue', bd=6, relief=RIDGE)
Cal_F.pack(side=TOP)
Receipt_F=Frame(ReceiptCal_F, bg='Powder Blue', bd=4, relief=RIDGE)
Receipt_F.pack(side=BOTTOM)
MenuFrame = Frame(root, bg="Cadet Blue", bd=10, relief=RIDGE)
MenuFrame.pack(side=LEFT)
Cost_F=Frame(MenuFrame, bg='Powder Blue', bd=4)
Cost_F.pack(side=BOTTOM)
Drinks_F=Frame(MenuFrame, bg='Cadet Blue', bd=10)
Drinks_F.pack(side=TOP)
Drinks_F=Frame(MenuFrame, bg='Powder Blue', bd=10, relief=RIDGE)
Drinks_F.pack(side=LEFT)
Cake_F=Frame(MenuFrame, bg='Powder Blue', bd=10, relief=RIDGE)
Cake_F.pack(side=RIGHT)
#=============================================Variables=====================================
var1=IntVar()
var2=IntVar()
var3=IntVar()
var4=IntVar()
var5=IntVar()
var6=IntVar()
var7=IntVar()
var8=IntVar()
var9=IntVar()
var10=IntVar()
var11=IntVar()
var12=IntVar()
var13=IntVar()
var14=IntVar()
var15=IntVar()
var16=IntVar()
DateofOrder = StringVar()
Receipt_Ref = StringVar()
PaidTax = StringVar()
SubTotal = StringVar()
TotalCost = StringVar()
CostofCakes = StringVar()
CostofDrinks = StringVar()
ServiceCharge = StringVar()
text_Input = StringVar()
operator =""
E_Latte=StringVar()
E_Espresso=StringVar()
E_Iced_Latte=StringVar()
E_Vale_Coffe=StringVar()
E_Cappucino=StringVar()
E_African_Coffee=StringVar()
E_American_Coffee=StringVar()
E_Iced_Cappuccino=StringVar()
E_School_Cake=StringVar()
E_Sunny_AO_Cake=StringVar()
E_Jonathan_YO_Cake=StringVar()
E_West_African_Cake=StringVar()
E_Lagos_Chocolate_Cake=StringVar()
E_Kilburn_Chocolate_Cake=StringVar()
E_Carlton_Hill_Chocolate_Cake=StringVar()
E_Queen_Park_Chocolate_Cake=StringVar()
E_Latte.set("0")
E_Espresso.set("0")
E_Iced_Latte.set("0")
E_Vale_Coffe.set("0")
E_Cappucino.set("0")
E_African_Coffee.set("0")
E_American_Coffee.set("0")
E_Iced_Cappuccino.set("0")
E_School_Cake.set("0")
E_Sunny_AO_Cake.set("0")
E_Jonathan_YO_Cake.set("0")
E_West_African_Cake.set("0")
E_Lagos_Chocolate_Cake.set("0")
E_Kilburn_Chocolate_Cake.set("0")
E_Carlton_Hill_Chocolate_Cake.set("0")
E_Queen_Park_Chocolate_Cake.set("0")
DateofOrder.set(time.strftime("%d/%m/%Y"))
#============================================Function declaration===============================================================================
def iExit():
iExit = tkinter.messagebox.askyesno("Exit Restaurant System", "Confirm if you want to exit")
if iExit > 0:
root.destroy()
return
def Reset():
PaidTax.set("")
SubTotal.set("")
TotalCost.set("")
CostofCakes.set("")
CostofDrinks.set("")
ServiceCharge.set("")
txtReceipt.delete("1.0".END)
E_Latte.set("0")
E_Espresso.set("0")
E_Iced_Latte.set("0")
E_Vale_Coffe.set("0")
E_Cappucino.set("0")
E_African_Coffee.set("0")
E_American_Coffee.set("0")
E_Iced_Cappuccino.set("0")
E_School_Cake.set("0")
E_Sunny_AO_Cake.set("0")
E_Jonathan_YO_Cake.set("0")
E_West_African_Cake.set("0")
E_Lagos_Chocolate_Cake.set("0")
E_Kilburn_Chocolate_Cake.set("0")
E_Carlton_Hill_Chocolate_Cake.set("0")
E_Queen_Park_Chocolate_Cake.set("0")
var1.set(0)
var2.set(0)
var3.set(0)
var4.set(0)
var5.set(0)
var6.set(0)
var7.set(0)
var8.set(0)
var9.set(0)
var10.set(0)
var11.set(0)
var12.set(0)
var13.set(0)
var14.set(0)
var15.set(0)
var16.set(0)
txtLatta.configure(state=DISABLED)
txtEspresso.configure(state=DISABLED)
txtIced_Latte.configure(state=DISABLED)
txtVale_Coffe.configure(state=DISABLED)
txtCappucino.configure(state=DISABLED)
txtAfrican_Coffee.configure(state=DISABLED)
txtAmerican_Coffee.configure(state=DISABLED)
txtIced_Cappucino.configure(state=DISABLED)
txtSchoolCake.configure(state=DISABLED)
txtSunny_AO_Cake.configure(state=DISABLED)
txtJonathan_YO_Cake.configure(state=DISABLED)
txtWest_African_Cake.configure(state=DISABLED)
txtLagos_Chocolate_Cake.configure(state=DISABLED)
txtKilburn_Chocolate_Cake.configure(state=DISABLED)
txtCarlton_Hill_Chocolate_Cake.configure(state=DISABLED)
txtE_Queen_Park_Chocolate_Cake.configure(state=DISABLED)
#=============================================Drinks=====================================
Latta = Checkbutton(Drinks_F, text="Latta", variable=var1, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=0, sticky=W)
Expresso = Checkbutton(Drinks_F, text="Expresso", variable=var2, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=1, sticky=W)
Iced_Latte = Checkbutton(Drinks_F, text="Iced Latta", variable=var3, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=2, sticky=W)
Vale_Coffe = Checkbutton(Drinks_F, text="Vale Coffe", variable=var4, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=3, sticky=W)
Cappucino = Checkbutton(Drinks_F, text="Cappucino", variable=var5, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=4, sticky=W)
African_Coffee = Checkbutton(Drinks_F, text="African Coffee", variable=var6, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=5, sticky=W)
American_Coffee = Checkbutton(Drinks_F, text="American Coffee", variable=var7, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=6, sticky=W)
Iced_Cappucino = Checkbutton(Drinks_F, text="Iced Cappucino", variable=var8, onvalue=1, offvalue=0, font=("arial",18,'bold'), bg="Powder Blue").grid(row=7, sticky=W)
#=============================================Entry Box for Drinks=====================================
txtLatte = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Latte, bd=8, width=6, justify=LEFT, state=DISABLED)
txtLatte.grid(row=0, column=1)
txtEspresso = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Espresso, bd=8, width=6, justify=LEFT, state=DISABLED)
txtEspresso.grid(row=1, column=1)
txtIced_Latte = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Iced_Latte, bd=8, width=6, justify=LEFT, state=DISABLED)
txtIced_Latte.grid(row=2, column=1)
txtVale_Coffe = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Vale_Coffe, bd=8, width=6, justify=LEFT, state=DISABLED)
txtVale_Coffe.grid(row=3, column=1)
txtCappucino = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Cappucino, bd=8, width=6, justify=LEFT, state=DISABLED)
txtCappucino.grid(row=4, column=1)
txtAfrican_Coffee = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_African_Coffee, bd=8, width=6, justify=LEFT, state=DISABLED)
txtAfrican_Coffee.grid(row=5, column=1)
txtAmerican_Coffee = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_American_Coffee, bd=8, width=6, justify=LEFT, state=DISABLED)
txtAmerican_Coffee.grid(row=6, column=1)
txtIced_Cappucino = Entry(Drinks_F, font=("arial",16,'bold'), textvariable=E_Iced_Cappuccino, bd=8, width=6, justify=LEFT, state=DISABLED)
txtIced_Cappucino.grid(row=7, column=1)
#=============================================Cakes=====================================
SchoolCake = Checkbutton(Cake_F, text="School Cake\t\t\t ", variable=var9, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=0, sticky=W)
Sunny_AO_Cake = Checkbutton(Cake_F, text="Sunday O Cake ", variable=var10, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=1, sticky=W)
Jonathan_YO_Cake = Checkbutton(Cake_F, text="Jonathan O Cake ", variable=var11, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=2, sticky=W)
West_African_Cake = Checkbutton(Cake_F, text="West African Cake ", variable=var12, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=3, sticky=W)
Logos_Chocolate_Cake = Checkbutton(Cake_F, text="Logos Chocolate Cake ", variable=var13, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=4, sticky=W)
Kilburn_Chocolate_Cake = Checkbutton(Cake_F, text="Kilburn Chocolate Cake ", variable=var14, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=5, sticky=W)
Carlton_Hill_Cake = Checkbutton(Cake_F, text="Carlton Hill Cake ", variable=var15, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=6, sticky=W)
Queen_Park_Cake = Checkbutton(Cake_F, text="Queen Park Cake ", variable=var16, onvalue=1, offvalue=0, font=("arial",16,'bold'),
bg="Powder Blue").grid(row=7, sticky=W)
#=============================================Entry Box for Cakes=====================================
txtSchoolCake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_School_Cake)
txtSchoolCake.grid(row=0, column=1)
txtSunny_AO_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Sunny_AO_Cake)
txtSunny_AO_Cake.grid(row=1, column=1)
txtJonathan_YO_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Jonathan_YO_Cake)
txtJonathan_YO_Cake.grid(row=2, column=1)
txtWest_African_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_West_African_Cake)
txtWest_African_Cake.grid(row=3, column=1)
txtLagos_Chocolate_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Lagos_Chocolate_Cake)
txtLagos_Chocolate_Cake.grid(row=4, column=1)
txtKilburn_Chocolate_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Kilburn_Chocolate_Cake)
txtKilburn_Chocolate_Cake.grid(row=5, column=1)
txtCarlton_Hill_Chocolate_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Carlton_Hill_Chocolate_Cake)
txtCarlton_Hill_Chocolate_Cake.grid(row=6, column=1)
txtE_Queen_Park_Chocolate_Cake = Entry(Cake_F, font=("arial",16,'bold'), bd=8, width=6, justify=LEFT, state=DISABLED, textvariable=E_Queen_Park_Chocolate_Cake)
txtE_Queen_Park_Chocolate_Cake.grid(row=7, column=1)
#=============================================Totals Cost================================================
lblCostofDrinks = Label(Cost_F, font=('arial',14,'bold'), text="Cost of Drinks\t", bg='Powder Blue', fg='Black')
lblCostofDrinks.grid(row=0,column=0,sticky=W)
txtCostofDrinks = Entry(Cost_F, bg="white", bd=7, textvariable=CostofDrinks, font=("arial", 14,'bold'), insertwidth=2, justify=RIGHT)
txtCostofDrinks.grid(row=0, column=1)
lblCostofCakes = Label(Cost_F, font=('arial',14,'bold'), text="Cost of Cakes ", bg='Powder Blue', fg='Black')
lblCostofCakes.grid(row=1,column=0,sticky=W)
txtCostofCakes = Entry(Cost_F, bg="white", bd=7, textvariable=CostofCakes, font=("arial",14,'bold'),insertwidth=2, justify=RIGHT)
txtCostofCakes.grid(row=1, column=1)
lblServiceCharge = Label(Cost_F, font=('arial',14,'bold'), text="Service Charge ", bg='Powder Blue', fg='Black')
lblServiceCharge.grid(row=2,column=0,sticky=W)
txtServiceCharge = Entry(Cost_F, bg="white", bd=7, textvariable=ServiceCharge, font=("arial",14,'bold'), insertwidth=2, justify=RIGHT)
txtServiceCharge.grid(row=2, column=1)
#=============================================Payment Information================================================
lblPaidTax = Label(Cost_F, font=('arial',14,'bold'), text="\tPaid Tax\t", bg='Powder Blue', fg='Black', bd=7)
lblPaidTax.grid(row=0,column=2,sticky=W)
txtPaidTax = Entry(Cost_F, bg="white", bd=7, textvariable=PaidTax, font=("arial", 14,'bold'), insertwidth=2, justify=RIGHT)
txtPaidTax.grid(row=0, column=3)
lblSubTotal = Label(Cost_F, font=('arial',14,'bold'), text="\tSub Total", bg='Powder Blue', fg='Black')
lblSubTotal.grid(row=1,column=2,sticky=W)
txtSubTotal = Entry(Cost_F, bg="white", bd=7, textvariable=SubTotal, font=("arial",14,'bold'),insertwidth=2, justify=RIGHT)
txtSubTotal.grid(row=1, column=3)
lblTotalCost = Label(Cost_F, font=('arial',14,'bold'), text="\tTotal Cost", bg='Powder Blue', fg='Black')
lblTotalCost.grid(row=2,column=2,sticky=W)
txtTotalCost = Entry(Cost_F, bg="white", bd=7, textvariable=TotalCost, font=("arial",14,'bold'), insertwidth=2, justify=RIGHT)
txtTotalCost.grid(row=2, column=3)
#=============================================Receipt================================================
txtReceipt = Text(Receipt_F, width=46, height=12, bg="white", bd=4, font=("arial",12,'bold'))
txtReceipt.grid(row=0, column=0)
#=============================================Buttons================================================
btnTotal = Button(Buttons_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="Total",
bg="powder blue").grid(row=0, column=0)
btnReceipt = Button(Buttons_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="Receipt",
bg="powder blue").grid(row=0, column=1)
btnReset = Button(Buttons_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="Reset",
bg="powder blue", command=Reset).grid(row=0, column=2)
btnExit = Button(Buttons_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="Exit",
bg="powder blue", command = iExit).grid(row=0, column=3)
#=============================================Calculator Display======================================================
def btnClick(numbers):
global operator
operator = operator + str(numbers)
text_Input.set(operator)
def btnClear():
global operator
operator = ""
text_Input.set("")
def btnEquals():
global operator
sumup = str(eval(operator))
text_Input.set(sumup)
operator = ""
txtDislplay = Entry(Cal_F, width=45, bg="white", bd=4, font=("arial",12,'bold'), justify=RIGHT, textvariable=text_Input)
txtDislplay.grid(row=0, column=0, columnspan=4, pady=1)
txtDislplay.insert(0, "0")
#=============================================Calculator Buttons================================================
btn7 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="7", command=lambda:btnClick(7)).grid(row=2, column=0)
btn8 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="8", command=lambda:btnClick(8)).grid(row=2, column=1)
btn9 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="9", command=lambda:btnClick(9)).grid(row=2, column=2)
btnAdd = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="+",
bg="powder blue", command=lambda:btnClick("+")).grid(row=2, column=3)
#=============================================Calculator Buttons================================================
btn4 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="4", command=lambda:btnClick(4)).grid(row=3, column=0)
btn5 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="5", command=lambda:btnClick(5)).grid(row=3, column=1)
btn6 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="6", command=lambda:btnClick(6)).grid(row=3, column=2)
btnSub = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="-",
bg="powder blue", command=lambda:btnClick("-")).grid(row=3, column=3)
#=============================================Calculator Buttons================================================
btn1 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="1", command=lambda:btnClick(1)).grid(row=4, column=0)
btn2 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="2", command=lambda:btnClick(2)).grid(row=4, column=1)
btn3 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="3", command=lambda:btnClick(3)).grid(row=4, column=2)
btnMulti = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="*",
bg="powder blue", command=lambda:btnClick("*")).grid(row=4, column=3)
#=============================================Calculator Buttons================================================
btn0 = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="0", command=lambda:btnClick(0)).grid(row=5, column=0)
btnClear = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="C",
bg="powder blue", command=btnClear).grid(row=5, column=1)
btnEquals = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="=",
bg="powder blue", command=btnEquals).grid(row=5, column=2)
btnDiv = Button(Cal_F, padx=16, pady=1, bd=7, fg="black", font=("arial",16,'bold'), width=4, text="/",
bg="powder blue", command=lambda:btnClick("/")).grid(row=5, column=3)
root.mainloop()