-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderMenu.py
More file actions
176 lines (144 loc) · 6.94 KB
/
orderMenu.py
File metadata and controls
176 lines (144 loc) · 6.94 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from tkinter import *
import csv
from tkinter import messagebox
class OrderMenuApp:
def __init__(self):
self.window = Tk()
self.window.attributes("-fullscreen", True)
self.menu_file = 'menu.csv'
self.billing_labels = self.read_labels_from_csv(self.menu_file)
self.menu_items = self.read_menu_from_csv(self.menu_file)
self.entry_widgets, self.total_labels, self.overall_total_label = self.display_billing_labels(self.billing_labels)
self.display_data_structure(self.menu_items)
self.display_ui()
def display_ui(self):
# Display the user interface
self.display_labels()
self.display_buttons()
self.window.mainloop()
def display_labels(self):
# Display the title and labels
titleLabel = Label(self.window, text="Welcome to,", font="times 20 bold")
titleLabel.place(x=650, y=20, anchor="center")
titleLabel2 = Label(self.window, text="Beach Side Restaurant", font="times 30 bold")
titleLabel2.place(x=650, y=60, anchor="center")
label1 = Label(self.window, text="Menu", font="times 28 bold")
label1.place(x=1100, y=70)
billLabel = Label(self.window, text="Order Here", font="times 28 bold")
billLabel.place(x=70, y=70)
def display_buttons(self):
# Display the buttons
place_order_button = Button(self.window, text="Place Order", width=25, height=3, command=self.display_order_summary)
place_order_button.place(x=580, y=600)
place_order_button.configure(bg="red")
exit_button = Button(self.window, text="Exit", width=20, command=self.window.destroy)
exit_button.place(x=600, y=700)
def display_order_summary(self):
# Display the order summary window
summary_window = Toplevel(self.window)
summary_window.title("Order Summary")
# Calculate the total price
total_price = sum([int(entry.get()) * float(item[1]) for entry, item in zip(self.entry_widgets, self.menu_items)])
# Display the order summary
summary_label = Label(summary_window, text="Your Order", font="times 20 bold")
summary_label.pack()
for entry, item, total_label in zip(self.entry_widgets, self.menu_items, self.total_labels):
quantity = int(entry.get())
item_name = item[0]
item_price = float(item[1])
total = quantity * item_price
summary_text = f"{item_name} x {quantity} = {total}"
summary_item_label = Label(summary_window, text=summary_text)
summary_item_label.pack()
total_label.config(text=f"Total Price: {total_price}")
confirm_button = Button(summary_window, text="Confirm Order", command=lambda: self.confirm_order(total_price))
confirm_button.pack()
def confirm_order(self, total_price):
# Get the order details
order_details = []
for entry, item in zip(self.entry_widgets, self.menu_items):
quantity = int(entry.get())
item_name = item[0]
item_price = float(item[1])
total = quantity * item_price
order_details.append([item_name, quantity, total])
# Write the order details to a CSV file
order_file = 'order_details.csv'
with open(order_file, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Item', 'Quantity', 'Total'])
writer.writerows(order_details)
writer.writerow(['', '', f'Total Price: {total_price}'])
messagebox.showinfo("Order Confirmation", "Order confirmed!")
for entry in self.entry_widgets:
entry.delete(0, END)
entry.insert(0, "0")
def display_billing_labels(self, labels):
# Display the billing labels and entry widgets
entry_values = []
total_values = []
for i, label in enumerate(labels):
label = Label(self.window, text=label, font="times 18")
label.place(x=20, y=120 + (i * 60))
entry = Entry(self.window)
entry.insert(0, "0")
entry.place(x=20, y=150 + (i * 60))
entry_values.append(entry)
total_label = Label(self.window, text="Total: 0", font="times 12")
total_label.place(x=200, y=150 + (i * 60))
total_values.append(total_label)
entry.bind("<KeyRelease>", lambda event, index=i: self.update_total(event, index, entry_values, total_values))
overall_total_label = Label(self.window, text="Overall Total: 0", font="times 12")
overall_total_label.place(x=600, y=300 + (i * 60))
return entry_values, total_values, overall_total_label
def update_total(self, event, index, entry_values, total_values):
# Update the total price based on the quantity entered
try:
amount = int(entry_values[index].get())
if amount < 11:
price = self.get_multiplier()[index]
total = amount * price
total_values[index].config(text="Total: Shs " + str(total))
overall_total = sum(int(entry.get()) * self.get_multiplier()[i] for i, entry in enumerate(entry_values))
self.overall_total_label.config(text="Overall Total: Shs " + str(overall_total))
else:
entry_values[index].delete(0, END)
total_values[index].config(text="Total: Shs 0")
except ValueError:
total_values[index].config(text="Total: Shs 0")
def read_menu_from_csv(self, file_path):
# Read the menu items from a CSV file
menu_items = []
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
menu_items.append((row[0], row[1]))
return menu_items
def display_data_structure(self, data):
# Display the menu items
for i, item in enumerate(data):
if len(item) >= 2:
label = Label(self.window, text=f"{item[0]} ---- Shs{item[1]}", font="times 18")
label.place(x=900, y=160 + (i * 40))
else:
print(f"Invalid data structure at index {i}: {item}")
def read_labels_from_csv(self, file_path):
# Read the billing labels from a CSV file
billing_labels = []
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
billing_labels.append(row[0])
return billing_labels
def get_multiplier(self):
# Get the prices from the menu file
prices = []
with open(self.menu_file, 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if len(row) >= 2:
price = float(row[1])
prices.append(price)
return prices
if __name__ == "__main__":
app = OrderMenuApp()