I want to categorize the food by category, set the category, and choose the food. I want the total price to rise after choosing food. The order coffee part is a problem for me. Coffee menus overlap with other categories. Also, if I press the order completed button, I want a receipt with a thank you message. What should I do?
My error message is
The menu you entered does not exist.
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/Users/mason/PycharmProjects/APCSP/APCSP.py", line 174, in <lambda>
btn_drink_1 = tk.Button(frame3, text="Iced Coffee\n($2.65)", padx="10", pady="10", width="10", command=lambda: drink_add('Iced Coffee'))
File "/Users/mason/PycharmProjects/APCSP/APCSP.py", line 60, in drink_add
total_price += this_price
TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType'
Here is my code
price_meal = {"Donut": 1.25, "Filled Donut": 1.50, "Apple Fritter": 2.95, "Cinnamon roll": 2.95, "Muffin": 2.95, "Scone": 2.95}
price_drink = {"Hot Tea": 1.95, "Hot Chocolate": 1.75, "Milk": 1.50, "Chocolate Milk": 1.95, "Soda": 2.25}
price_coffees = {"Iced Coffee": 2.65, "Cold Brew": 3.95, "Iced Americano" :2.45, "Mochatella":4.25, "Iced Mochatella": 4.75, "Cafe Caramel/Mocha": 4.70}
order_meal = {}
order_drink = {}
order_coffees = {}
total_price = 0
def show_meal():
btn_meal.configure(bg="yellow")
btn_drink.configure(bg="white")
frame4.pack_forget()
frame3.pack_forget()
frame2.pack(fill="both", expand=True)
frame4.pack(fill="both", expand=True)
def show_drink():
btn_meal.configure(bg="white")
btn_drink.configure(bg="yellow")
frame4.pack_forget()
frame2.pack_forget()
frame3.pack(fill="both", expand=True)
frame4.pack(fill="both", expand=True)
def show_coffees():
btn_meal.configure(bg="white")
btn_drink.configure(bg="yellow")
frame4.pack_forget()
frame2.pack_forget()
frame3.pack(fill="both", expand=True)
frame4.pack(fill="both", expand=True)
def meal_add(m):
global price_meal, order_meal, total_price
if m not in price_meal:
print("The menu you entered does not exist.")
this_price = price_meal.get(m)
total_price += this_price
if m in order_meal:
order_meal[m] = order_meal.get(m) + 1
else:
order_meal[m] = 1
print_order()
print_price()
def drink_add(m):
global price_drink, order_drink, total_price
if m not in price_drink:
print("The menu you entered does not exist.")
this_price = price_drink.get(m)
total_price += this_price
if m in order_drink:
order_drink[m] = order_drink.get(m) + 1
else:
order_drink[m] = 1
print_order()
print_price()
def coffees_add(m):
global price_coffees, order_coffees, total_price
if m not in price_coffees:
print("The menu you entered does not exist.")
this_price = price_coffees.get(m)
total_price += this_price
if m in order_coffees:
order_drink[m] = order_coffees.get(m) + 1
else:
order_coffees[m] = 1
print_order()
print_price()
def print_order():
global order_meal, order_drink, order_coffees
tmp = ""
price_tmp = 0
for i in order_meal:
price_tmp = price_meal[i] * order_meal.get(i)
tmp = tmp + i + " X " + str(order_meal.get(i)) + " = " + str(price_tmp)+"\n"
for i in order_drink:
price_tmp = price_drink[i] * order_drink.get(i)
tmp = tmp + i + " X " + str(order_drink.get(i)) + " = " + str(price_tmp)+"\n"
for i in order_coffees:
price_tmp = price_coffees[i] * order_coffees.get(i)
tmp = tmp + i + " X " + str(order_coffees.get(i)) + " = " + str(price_tmp)+"\n"
text_1.delete('1.0', tk.END)
text_1.insert(tk.INSERT, tmp)
def order_end():
global total_price, order_meal, order_drink, order_coffees
total_price = 0
del order_meal
del order_drink
del order_coffees
order_meal = {}
order_drink = {}
order_coffees = {}
print_price()
print_order()
show_meal()
def print_price():
global total_price
label_price.configure(text=str(total_price))
window = tk.Tk()
window.title("Brunch Cafe")
window.geometry("800x400+500+300")
window.resizable(False, False)
frame1 = tk.Frame(window, width="800", height="10")
frame1.pack(fill="both")
frame2 = tk.Frame(window, width="800")
frame2.pack(fill="both", expand=True)
frame3 = tk.Frame(window, width="800")
frame3.pack(fill="both", expand=True)
frame4 = tk.Frame(window, width="800")
# frame4.pack(fill="both", expand=True)
frame5 = tk.Frame(window, width="800", height="10")
frame5.pack(fill="both", expand=True)
btn_meal = tk.Button(frame1, text="meal", padx="10", pady="10", bg="yellow", command=show_meal)
btn_meal.grid(row=0, column=0, padx=10, pady=10)
btn_drink = tk.Button(frame1, text="drinks", padx="10", pady="10", bg="white", command=show_drink)
btn_drink.grid(row=0, column=1, padx=10, pady=10)
btn_end = tk.Button(frame1, text="Order Completed", padx="10", pady="10", command=order_end)
btn_end.grid(row=0, column=2, padx=10, pady=10)
label_price = tk.Label(frame1, text="0 dollars", width="20", padx=10, pady="10", fg="blue", font='Arial 15')
label_price.grid(row=0, column="3", padx="10", pady="10")
# Meal
btn_meal_1 = tk.Button(frame2, text="Donut\n($1.25)", padx="10", pady="10", width="10", command=lambda: meal_add('Donut'))
btn_meal_1.grid(row=0, column=0, padx=10, pady=10)
btn_meal_2 = tk.Button(frame2, text="Filled Donut\n($1.50)", padx="10", pady="10", width="10", command=lambda: meal_add('Filled Donut'))
btn_meal_2.grid(row=0, column=1, padx=10, pady=10)
btn_meal_3 = tk.Button(frame2, text="Cinnamon roll\n($2.95)", padx="10", pady="10", width="10", command=lambda: meal_add('Cinnamon roll'))
btn_meal_3.grid(row=0, column=2, padx=10, pady=10)
btn_meal_4 = tk.Button(frame2, text="Muffin\n($2.95)", padx="10", pady="10", width="10", command=lambda: meal_add('Muffin'))
btn_meal_4.grid(row=0, column=3, padx=10, pady=10)
btn_meal_5 = tk.Button(frame2, text="Scone\n($2.95)", padx="10", pady="10", width="10", command=lambda: meal_add('Scone'))
btn_meal_5.grid(row=0, column=4, padx=10, pady=10)
# Coffees
btn_drink_1 = tk.Button(frame3, text="Iced Coffee\n($2.65)", padx="10", pady="10", width="10", command=lambda: drink_add('Iced Coffee'))
btn_drink_1.grid(row=0, column=0, padx=10, pady=10)
btn_drink_2 = tk.Button(frame3, text="Cold Brew\n($3.95)", padx="10", pady="10", width="10", command=lambda: drink_add('Cold Brew'))
btn_drink_2.grid(row=0, column=1, padx=10, pady=10)
btn_drink_3 = tk.Button(frame3, text="Iced Americano\n($2.45)", padx="10", pady="10", width="10", command=lambda: drink_add('Iced Americano'))
btn_drink_3.grid(row=0, column=2, padx=10, pady=10)
btn_drink_4 = tk.Button(frame3, text="Mochatella\n($4.25)", padx="10", pady="10", width="10", command=lambda: drink_add('Mochatella'))
btn_drink_4.grid(row=0, column=3, padx=10, pady=10)
btn_drink_6 = tk.Button(frame3, text="Iced Mochatella\n($4.75)", padx="10", pady="10", width="10", command=lambda: drink_add('Iced Mochatella'))
btn_drink_6.grid(row=0, column=4, padx=10, pady=10)
btn_drink_7 = tk.Button(frame3, text="Cafe Caramel/Mocha\n($4.70)", padx="10", pady="10", width="10", command=lambda: drink_add('Cafe Caramel/Mocha'))
btn_drink_7.grid(row=0, column=4, padx=10, pady=10)
# Drinks
btn_drink_1 = tk.Button(frame4, text="Hot Tea\n($1.95)", padx="10", pady="10", width="10", command=lambda: drink_add('Hot Tea'))
btn_drink_1.grid(row=0, column=0, padx=10, pady=10)
btn_drink_2 = tk.Button(frame4, text="Hot Chocolate\n($1.75)", padx="10", pady="10", width="10", command=lambda: drink_add('Hot Chocolate'))
btn_drink_2.grid(row=0, column=1, padx=10, pady=10)
btn_drink_3 = tk.Button(frame4, text="Milk\n($1.50)", padx="10", pady="10", width="10", command=lambda: drink_add('Milk'))
btn_drink_3.grid(row=0, column=2, padx=10, pady=10)
btn_drink_4 = tk.Button(frame4, text="Soda\n($2.25)", padx="10", pady="10", width="10", command=lambda: drink_add('Soda'))
btn_drink_4.grid(row=0, column=3, padx=10, pady=10)
# Order list
text_1 = tk.Text(frame5, height="10")
text_1.pack()
window.mainloop()