-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmenu.py
More file actions
158 lines (128 loc) · 5.96 KB
/
menu.py
File metadata and controls
158 lines (128 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import tkinter as tk
from tkinter import *
from PIL import Image, ImageTk
import sys
import os
import textwrap
from dbconnect import get_menu_items, add_to_cart_db
import subprocess
# Initialize Tkinter
root = tk.Tk()
root.title("Feasto")
root.state('zoomed')
root.configure(bg="black") # Set full background to black
# Near the top of the file
table_number = sys.argv[2] if len(sys.argv) > 2 else "N/A"
# Function to go back to restaurant selection
def open_resto():
root.destroy()
subprocess.Popen(["python", "resto.py", table_number])
# Function to open checkout
def open_checkout():
root.destroy()
subprocess.Popen(["python", "checkout.py", restaurant_name, table_number])
# Function to add item to cart and update button text
def add_to_cart(order_id, dish_name, price, restaurant_name, button):
try:
add_to_cart_db(order_id, restaurant_name, dish_name, price, quantity=1)
print(f"✅ Added to cart: {dish_name}")
button.config(text="Added ✅", state="disabled", bg="white", fg="black")
button.unbind("<Enter>")
button.unbind("<Leave>")
except Exception as e:
print(f"❌ Failed to add to cart: {e}")
# Button Hover Effects
def on_enter_checkout(e): checkout_button.config(bg="gray")
def on_leave_checkout(e): checkout_button.config(bg="black")
def on_enter_exit(e): exit_button.config(bg="gray")
def on_leave_exit(e): exit_button.config(bg="black")
def on_enter_add(e): e.widget.config(bg="darkorange")
def on_leave_add(e): e.widget.config(bg="orange")
# Get restaurant name and menu items
if len(sys.argv) < 2:
restaurant_name = "Domino's"
menu_items = [
(4, "Cheese Pizza", 19, "Cheese, tomato, corn", "images/menu/cheese_pizza.jpg"),
(5, "Paneer Pizza", 5, "Spicy paneer, bell peppers, mushroom, loads of cheese", "images/menu/paneer_pizza.jpg"),
(6, "Veggie Supreme", 7, "Capsicum, onion, olives, cheese", "images/menu/veggie_supreme.jpg"),
]
else:
restaurant_name = sys.argv[1]
menu_items = get_menu_items(restaurant_name)
# Get screen dimensions
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
# Title Label
title_label = tk.Label(root, text=f"{restaurant_name} Menu", font=("Arial", 28, "bold"), fg="white", bg="black")
title_label.pack(pady=20)
# Add logo2.png in top right corner
logo_size = 100
try:
logo_image = Image.open("images/logo2.png").resize((logo_size, logo_size))
logo_photo = ImageTk.PhotoImage(logo_image)
logo_label = tk.Label(root, image=logo_photo, bg="black")
logo_label.image = logo_photo # Keep a reference
logo_label.place(x=screen_width - logo_size - 30, y=10)
except:
print("Logo image not found")
# Scrollable Menu Frame
scroll_canvas = tk.Canvas(root, width=screen_width, height=screen_height - 200, highlightthickness=0, bg="black")
scroll_canvas.place(relx=0.07, rely=0.15, relwidth=0.96, relheight=0.75)
# Scrollbar
scrollbar = tk.Scrollbar(root, orient="vertical", command=scroll_canvas.yview)
scrollbar.place(relx=0.98, rely=0.15, relheight=0.75)
scroll_canvas.configure(yscrollcommand=scrollbar.set)
# Scroll Frame
scroll_frame = tk.Frame(scroll_canvas, bg="black")
scroll_window = scroll_canvas.create_window((0, 0), window=scroll_frame, anchor="n", width=screen_width - 300)
# Store images to prevent garbage collection
image_refs = []
y_position = 20
for item in menu_items:
order_id, dish_name, price, description, image_path = item
wrapped_description = "\n".join(textwrap.wrap(description, width=75))
text = f" {dish_name} - ₹{price}\n {wrapped_description}"
# Menu Item Frame
item_frame = tk.Frame(scroll_frame, bg="black", padx=10, pady=10, highlightbackground="gray", highlightthickness=1)
item_frame.pack(fill="x", padx=20, pady=10)
# Load and place image
try:
if os.path.exists(image_path):
item_image = Image.open(image_path).resize((80, 80), Image.LANCZOS)
else:
print(f"Image not found for {dish_name}, using default image.")
item_image = Image.open("images/default.jpg").resize((80, 80), Image.LANCZOS)
item_photo = ImageTk.PhotoImage(item_image)
image_refs.append(item_photo)
image_label = tk.Label(item_frame, image=item_photo, bg="black")
image_label.pack(side="left", padx=10)
except Exception as e:
print("Image load error:", e)
# Menu Text Label
text_label = tk.Label(item_frame, text=text, font=("Arial", 16), fg="white", bg="black", anchor="w", justify="left")
text_label.pack(side="left", padx=10, expand=True, fill="both")
# Add to Cart Button
add_button = tk.Button(item_frame, text="Add to Cart", font=("Arial", 10, "bold"), bg="orange", fg="black", padx=12, pady=8, relief="ridge", borderwidth=2)
add_button.config(command=lambda oid=order_id, name=dish_name, pr=price, btn=add_button: add_to_cart(oid, name, pr, restaurant_name, btn))
add_button.pack(side="right", padx=10)
# Add hover effects
add_button.bind("<Enter>", on_enter_add)
add_button.bind("<Leave>", on_leave_add)
# Update Scroll Region
scroll_frame.update_idletasks()
scroll_canvas.config(scrollregion=scroll_canvas.bbox("all"))
# Bottom Buttons Frame
bottom_frame = tk.Frame(root, bg="black")
bottom_frame.place(relx=0.5, rely=0.96, anchor="center")
# Checkout Button
checkout_button = tk.Button(bottom_frame, text="Checkout 🛒", font=("Arial", 14, "bold"), command=open_checkout, bg="#ff5f5f", fg="white", padx=20, pady=10, relief="ridge", borderwidth=2, width=15)
checkout_button.pack(side="left", padx=10)
checkout_button.bind("<Enter>", on_enter_checkout)
checkout_button.bind("<Leave>", on_leave_checkout)
# Back Button
exit_button = tk.Button(bottom_frame, text="⬅ Back", font=("Arial", 14, "bold"), command=open_resto, bg="#383838", fg="white", padx=20, pady=10, relief="ridge", borderwidth=2, width=15)
exit_button.pack(side="right", padx=10)
exit_button.bind("<Enter>", on_enter_exit)
exit_button.bind("<Leave>", on_leave_exit)
# Run the Tkinter loop
root.mainloop()