0% found this document useful (0 votes)
3 views

Documentation Final

Uploaded by

Shone Bijju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Documentation Final

Uploaded by

Shone Bijju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

TABLE OF CONTENTS

SNO DESCRIPTION

01 ACKNOWLEDGEMENT

02 SYSTEM REQUIREMENTS and SPECIFICATIONS

03 SYNOPSIS

04 DATA BASE DICTIONARY

05 SOURCE CODE

06 OUTPUT

07 BIBLIOGRAPHY

1
ACKNOWLEDGEMENT
In the successful completion of this project, many people have bestowed
upon me their blessings and sincere support. I utilize this moment to express
my heart-felt gratitude to all the people who have been associated with this
project.

Primarily, I thank the Lord Almighty for His blessings that helped me combat
the various hurdles that arose during the course of the project.

I want to take this opportunity to thank our Principal Rev. Dr.Varghese


Kachappilly CMI for his blessings and guidance.

I offer my sincere gratitude to my teacher Gibi Gangadharan whose valuable


guidance has helped patch this project and make it a fool proof success. Her
suggestions and instructions have served as the major contribution towards
the accomplishment of this project within the limited time frame.

A project is a bridge between theoretical and practical learning and with this
thinking I worked on the project and made it successful due to the timely
support of my classmates. I would like to thank my friends for the knowledge
they shared.

Last but not the least; I thank my parents for the undeniable support they
rendered.

2
SYSTEM REQUIREMENTS AND SPECIFICATIONS

Hardware Specifications

1. System – 32-bit operating system


2. Processor – AMD Sempron™145 Processor 2.80 GHz
3. Speed – 2.80 GHz
4. Memory – 2.00 GB
5. Hard Disk -70.3 GB

Software Specifications
1. Operating System – Windows 10
2. Development Environment –Python IDLE , Tkinter
3. Language Used – Python 3.10.10
4. Front End – Python
5. Back End – Mysql

3
SYNOPSIS
Our project is a unique food delivery app that would enable people to order
food online.

The user can start using the app by creating an account. After signing up,
the user can access the app by entering their Username and Password.

After logging in , the user will reach the homepage. The homepage consists
of 10 restaurants. The user can order food from a particular restaurant by
clicking the restaurant icon. After clicking the icon the restaurant menu is
displayed in a separate side window.

The user can add food by clicking on the ‘+’ icon next to the item’s image
and increase or decrease the quantity by clicking on the respective icons
.The items are then added to the cart.

Now, the user can go to the homepage and click on the cart icon in the top
right corner to see the food they ordered and the bill is displayed. After
clicking on the place order button your delivery address will be displayed
and your order is successfully placed .

4
DATABASE DICTIONARY
desc users;
Field Type Null Key Default Extra

user_id int NO PRI NULL Stores primary


key user_id

username varchar(60) YES UNI NULL Stores username


(unique)

password varchar(20) YES NULL Stores password

phone_no varchar(10) YES NULL Stores phoneno

address varchar(200) YES NULL Stores address

desc restaurant;
Field Type Null Key Default Extra

Restaurant_id int NO PRI NULL Assigns id to each


restaurant

Restaurant_name varchar(30) YES NULL Stores restaurant


name

address varchar(200) YES NULL Stores restaurant


address

Cuisine varchar(20) YES NULL Stores cuisine of


restaurant

desc menu;
Field Type Null Key Default Extra

Item_id char(9) NO NULL Assigns id to each


item

5
Restaurant_id int YES MUL NULL Stores restaurant
id

Item_Name varchar(100) YES NULL Stores item_name

Price int YES NULL Stores price

desc cart;
Field Type Null Key Default Extra

user_id int YES MUL NULL Stores userid

restaurant_id int NO NULL Stores restaurant


id

order_date date YES NULL Stores date of


order

item_id char(9) NO NULL Stores id of


ordered item

item_name varchar(100) YES NULL Stores item name

quantity int YES NULL Stores quantity of


ordered item

price decimal(10,2) YES NULL Stores price

6
SOURCE CODE

from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage,


Label,messagebox,Scrollbar,Frame,IntVar,Toplevel,TclError
from PIL import Image, ImageTk
import os
import mysql.connector as ms
from datetime import datetime

Restaurant_Interface=None
cart=None
account_setting=None
image_references=[]

cn=ms.connect(host='localhost',user='root',passwd='root')
cur=cn.cursor()

def databasecreate(): #Function to create database and insert necessary


records
global cn,cur
cur.execute("CREATE DATABASE IF NOT EXISTS Food_Delivery_System")
cur.execute("USE Food_Delivery_System")

cur.execute("""
CREATE TABLE IF NOT EXISTS Users (
user_id INT PRIMARY KEY,
username VARCHAR(60) UNIQUE,
password VARCHAR(20),
phone_no varchar(10),
address VARCHAR(200)
)
""")

7
cn.commit()

cur.execute("""
CREATE TABLE IF NOT EXISTS Restaurant (
Restaurant_id INT(7) PRIMARY KEY,
Restaurant_name VARCHAR(30),
address VARCHAR(200),
Cuisine VARCHAR(20)
)
""")

cn.commit()

cur.execute("""
CREATE TABLE IF NOT EXISTS MENU (
Item_id CHAR(9) NOT NULL,
Restaurant_id INT(7) NOT NULL,
Item_Name VARCHAR(100),
Price INT(5),
FOREIGN KEY (Restaurant_id) REFERENCES Restaurant(Restaurant_id)
)
""")

cn.commit()

cur.execute("""
CREATE TABLE IF NOT EXISTS cart (
user_id INT,
restaurant_id INT(7) NOT NULL,
order_date DATE,
item_id char(9) NOT NULL,
item_name VARCHAR(100),
quantity INT,
price DECIMAL(10, 2),
FOREIGN KEY (user_id) REFERENCES Users(user_id)
)

8
""")

cn.commit()

def is_table_empty(table_name):
cur.execute(f"SELECT COUNT(*) FROM {table_name}")
count = cur.fetchone()[0]
return count == 0

restaurants = [
(1, 'Real Arabia', 'Mahatma Gandhi Rd, Atlantis, Ravipuram, Kochi', 'Arabic'),
(2, 'Zaatar Restaurant', 'Service Rd, Palarivattom, Kochi', 'Arabic'),
(3, 'Periyar Restaurant', 'Edapally - Panvel Hwy, Cheranallur, Kochi', 'Seafood'),
(4, 'Tharavadu Seafood Restaurant', 'NH 66, Cheranallur, Kochi', 'Seafood'),
(5, 'Supreme Upper Crust', 'Chalikkavattom, Vennala, Kochi', 'Continental'),
(6, 'Grand Entree', 'Chalikkavattom, Geetanjali Junction, Kochi', 'Continental'),
(7, 'Sethi Da Dhaba', 'Jawahar Nagar, Kadavanthra, Kochi', 'North Indian'),
(8, 'Urban Paratha', 'RP arcade, Ponnurunni, Vyttila, Kochi', 'North Indian'),
(9, 'Chiyang Restaurant', 'Sahodaran Ayyappan Rd, Kadavanthra, Kochi', 'Chinese'),
(10, 'Malaya Restaurant', 'Civil Line Rd, Sonia Nagar, Palarivattom, Kochi', 'Chinese'),
]

restaurant_query = """INSERT INTO Restaurant (Restaurant_id, Restaurant_name,


address, Cuisine)
VALUES (%s, %s, %s, %s)"""

if is_table_empty("Restaurant"):
cur.executemany(restaurant_query, restaurants)
cn.commit()

menu_items = [
('ITEM001', 1, 'Shawarma', 250),
('ITEM002', 1, 'Al Faham', 280),
('ITEM003', 1, 'Barbecue', 570),

9
('ITEM004', 1, 'Afghani Chicken', 550),
('ITEM005', 1, 'Pepper Wings', 360),

('ITEM006', 9, 'Chilly Chicken', 300),


('ITEM007', 9, 'Schezwan Chicken', 380),
('ITEM008', 9, 'Chicken Manchurian', 285),
('ITEM009', 9, 'Mushroom Manchurian', 140),
('ITEM010', 9, 'Gobi Schezwan', 140),

('ITEM011', 10, 'Ginger Chicken', 180),


('ITEM012', 10, 'Garlic Chicken', 180),
('ITEM013', 10, 'Paneer Garlic', 150),
('ITEM014', 10, 'Paneer Ginger', 150),
('ITEM015', 10, 'Kebab', 360),

('ITEM016', 2, 'Kozi Rice', 150),


('ITEM017', 2, 'Chicken Biryani', 250),
('ITEM018', 2, 'Kozi Theez', 250),
('ITEM019', 2, 'Arabian Shaz Chicken', 330),
('ITEM020', 2, 'Arabian Masala', 330),

('ITEM021', 3, 'Brown Crab', 220),


('ITEM022', 3, 'American Lobster', 230),
('ITEM023', 3, 'Mantis Shrimp', 230),
('ITEM024', 3, 'Butter Clam', 150),
('ITEM025', 3, 'Sea Urchin', 150),

('ITEM026', 4, 'Podimeen fry', 220),


('ITEM027', 4, 'Oysters', 220),
('ITEM028', 4, 'Karimeen', 320),
('ITEM029', 4, 'Squid Roast', 100),
('ITEM030', 4, 'Kozhuva Peera', 350),

('ITEM031', 7, 'Kadayi Chicken', 325),


('ITEM032', 7, 'Punjabi Chicken', 305),
('ITEM033', 7, 'Pepper Chicken', 320),
('ITEM034', 7, 'Chicken Tikka Masala', 330),
('ITEM035', 7, 'Butter Naan', 80),

10
('ITEM036', 8, 'Amritsari Chole', 150),
('ITEM037', 8, 'Bhature', 250),
('ITEM038', 8, 'Kashmiri Rogan Josh', 250),
('ITEM039', 8, 'Dal-Bati Churma', 320),
('ITEM040', 8, 'Dilli ki Chaat', 320),

('ITEM041', 5, 'Yorkshire Pudding', 150),


('ITEM042', 5, 'Sunday Roast', 220),
('ITEM043', 5, 'Kidney Pie', 340),
('ITEM044', 5, 'Batter Fish', 400),
('ITEM045', 5, 'Baked Soled Fillets', 405),

('ITEM046', 6, 'Spinach Tempura', 180),


('ITEM047', 6, 'Honey Chilli Potato', 210),
('ITEM048', 6, 'Dragon Vegetables', 220),
('ITEM049', 6, 'Shredded Lamb', 420),
('ITEM050', 6, 'Honey Glazed Chicken', 380)
]

insert_query = "INSERT INTO MENU (Item_id, Restaurant_id, Item_Name, Price)


VALUES (%s, %s, %s, %s)"

if is_table_empty("MENU"):
cur.executemany(insert_query, menu_items)
cn.commit()

cn=cn=ms.connect(host='localhost',user='root',passwd='root',database='food_delivery
_system')
cur=cn.cursor()

def login_func(): #login window creation


global login
login = Tk()
login.title("Login")
login.geometry("1012x569")

11
login.configure(bg="#F7F5E6")
login_canvas = Canvas(
login,
bg="#F7F5E6",
height=569,
width=1012,
bd=0,
highlightthickness=0,
relief="ridge"
)

login_canvas.place(x=0, y=0)
box_bg_image = PhotoImage(file=r"D:\food
delivery\assets\loginsignup\login_signup_box.png")
box_bg = login_canvas.create_image(
761,
284.5,
image=box_bg_image
)

login_canvas.create_text(
690.2,
114.4,
anchor="nw",
text="LOGIN",
fill="#282727",
font=("IstokWeb", 33, "bold")
)

entry_image_1 = PhotoImage(file=r"D:\food
delivery\assets\loginsignup\entrybox.png")
entry_bg_1 = login_canvas.create_image(
761.4,
207.2,
image=entry_image_1
)
login_username = Entry(
bd=0,

12
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
login_username.place(
x=638.5,
y=192.2,
width=245.7,
height=30.9
)

entry_image_2 = PhotoImage(file=r"D:\food
delivery\assets\loginsignup\entrybox.png")
entry_bg_2 = login_canvas.create_image(
761.4,
284.7,
image=entry_image_2
)
login_password = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0,
show="*"
)
login_password.place(
x=638.5,
y=269.7,
width=245.7,
height=30.9
)

login_canvas.create_text(
634.8,
171.9,
anchor="nw",
text="Username",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,'bold')

13
)

login_canvas.create_text(
634.8,
249.4,
anchor="nw",
text="Password",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,'bold')
)

signin_button_image = PhotoImage(file=r"D:\food
delivery\assets\loginsignup\signin_button.png")
signin_button = Button(
image=signin_button_image,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda: validate_login(login, login_username, login_password,
login_status),
relief="flat"
)
signin_button.place(
x=681.2,
y=332.2,
width=160.3,
height=40.0
)

login_canvas.create_text(
659.1,
442.4,
anchor="nw",
text="Don’t have an account?",
fill="#303030",
font=("Inter Bold", 12 * -1,'bold')

14
)

signup_button_image = PhotoImage(file=r"D:\food
delivery\assets\loginsignup\signup_button.png")
signup_button = Button(
image=signup_button_image,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",
activeforeground="white",
fg="white",
highlightthickness=0,
command=signupfunc,
relief="flat"
)
signup_button.place(
x=793.8,
y=441.8,
width=45.8,
height=18.9
)

pan_img = PhotoImage(file=r"D:\food delivery\assets\loginsignup\pan.png")


pan = login_canvas.create_image(
215.0,
295.9,
image=pan_img
)

egg_img = PhotoImage(file=r"D:\food delivery\assets\loginsignup\egg.png")


egg = login_canvas.create_image(
345.0,
280.9,
image=egg_img
)

login_status = Label(login, text="", font=("Helvetica", 12),


bg="#FFD966",fg="#FFD966")

15
login_status.place(x=650, y=380)

login.resizable(False, False)
login.mainloop()

def validate_login(login, login_username, login_password, login_status): #To


check/validate entered username & password
entered_username = login_username.get()
entered_password = login_password.get()
cur.execute("select username,password from users")
validate=cur.fetchall() #list of all existing username and passwords

if (entered_username,entered_password) in validate:
cur.execute("select user_id from users where username=%s",(entered_username,))
user_idfetch=cur.fetchone()

global user_id
user_id=user_idfetch[0] #stores user_id as global variable for further table
insertions

login.destroy()
mainwindowinterface()

else:
login_status.config(text="Incorrect username or password",
fg="red",bg='#FFD966')

def signupfunc(): #signup window creation


login.destroy()
global signup
signup = Tk()
signup.title("Signup")
signup.geometry("1012x569")

16
signup.configure(bg = "#F7F5E6")

signup_canvas = Canvas(
signup,
bg = "#F7F5E6",
height = 569,
width = 1012,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)

signup_canvas.place(x = 0, y = 0)
signup_box_img = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\login_signup_box.png")
signup_box = signup_canvas.create_image(
760.7,
284.5,
image=signup_box_img
)

signup_canvas.create_text(
704.1,
114.3,
anchor="nw",
text="SignUp",
fill="#282727",
font=("IstokWeb Bold", 33 * -1,"bold")
)

entry_image_1 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_1 = signup_canvas.create_image(
761.1,
195.0,
image=entry_image_1
)
signup_username = Entry(

17
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
signup_username.place(
x=638.2,
y=180.0,
width=245.6,
height=30.9
)

entry_image_2 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_2 = signup_canvas.create_image(
761.1,
254.5,
image=entry_image_2
)
signup_password = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0,
show="*"
)
signup_password.place(
x=638.2,
y=239.6,
width=245.6,
height=30.9

signup_canvas.create_text(
634.6,
159.7,
anchor="nw",
text="Username",

18
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

entry_image_3 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_3 = signup_canvas.create_image(
761.1,
314.1,
image=entry_image_3
)
signup_phoneno = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
signup_phoneno.place(
x=638.2,
y=299.1,
width=245.6,
height=30.9
)

signup_canvas.create_text(
634.6,
278.8,
anchor="nw",
text="Phone No",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

entry_image_4 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_4 = signup_canvas.create_image(
761.1,
373.7,
image=entry_image_4

19
)
signup_address = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
signup_address.place(
x=638.2,
y=358.7,
width=245.6,
height=30.9
)

signup_canvas.create_text(
634.6,
338.3,
anchor="nw",
text="Address",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

signup_canvas.create_text(
634.6,
219.2,
anchor="nw",
text="Password",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

create_signup_img = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\create_signup_button.png")
create_signup_button = Button(
image=create_signup_img,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",

20
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda:
signupvalidate(signup,signup_username,signup_password,signup_
phoneno,signup_address),
relief="flat"
)
create_signup_button.place(
x=680.9,
y=416.3,
width=160.2,
height=40.0
)

pan_img1 = PhotoImage(file=r"D:\food delivery\assets\loginsignup\pan.png")


pan1 = signup_canvas.create_image(
215.0,
295.9,
image=pan_img1
)

egg_img1 = PhotoImage(file=r"D:\food delivery\assets\loginsignup\egg.png")


egg1 = signup_canvas.create_image(
345.0,
280.9,
image=egg_img1
)
signup.resizable(False, False)

signup.mainloop()

#function to validate entered signup details


def signupvalidate(signup, signup_username, signup_password, signup_phoneno,
signup_address):
signup_flag = False

21
entered_username = signup_username.get()
entered_password = signup_password.get()
entered_phoneno = signup_phoneno.get()
entered_address = signup_address.get()

cur.execute("SELECT username FROM users")


usernamevalidate = cur.fetchall()

if (entered_username,) in usernamevalidate:
messagebox.showerror("Error", "Username already Taken")
elif entered_username=='':
messagebox.showerror("Error", "Please enter a username")
elif entered_password=='':
messagebox.showerror("Error", "Please enter a password")

elif entered_phoneno=='' or not entered_phoneno.isdigit() or


len(entered_phoneno)!=10:
messagebox.showerror("Error", "Invalid phoneno")

elif entered_address=='':
messagebox.showerror("Error", "Please enter an address")

else:
signup_flag = True

if signup_flag==True:
cur.execute("SELECT MAX(user_id) FROM users")
maxid = cur.fetchone() #fetches maximum user id

userid = maxid[0] + 1 if maxid[0] else 101 #auto increments user_id for each new
user

#inserting new user into users table


cur.execute(
"INSERT INTO users (user_id, username, password, phone_no, address) VALUES
(%s, %s, %s, %s, %s)",
(userid, entered_username, entered_password, entered_phoneno,
entered_address)

22
)

cn.commit()

global user_id
user_id=userid

signup.destroy()
mainwindowinterface()

def mainwindowinterface(): #creating interface of homepage


global cart
global account_setting

if cart is not None:


try:
if cart.winfo_exists():
cart.destroy()
except TclError:
cart = None

if account_setting is not None:


try:
if account_setting.winfo_exists():
account_setting.destroy()
except TclError:
account_setting = None

global mainwindow
mainwindow = Tk()
mainwindow.title("Homepage")
mainwindow.geometry("1012x569")
mainwindow.resizable(False, False)

23
menu_image_path = r"D:\food delivery\assets\Mainwindow\menubar.png"
menu_image = Image.open(menu_image_path)
menu_image = menu_image.resize((1012, 74), Image.LANCZOS)
menu_photo = ImageTk.PhotoImage(menu_image)

menu_bar = Label(mainwindow, image=menu_photo)


menu_bar.pack(side="top", fill="x")

cart_img = PhotoImage(file=r"D:\food delivery\assets\Mainwindow\cart.png")


cart_btn = Button(
menu_bar,
image=cart_img,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda: cartinterface(mainwindow),
relief="flat"
)
cart_btn.place(
x=758.0,
y=22.25,
width=119.0,
height=35.7
)

account_img = PhotoImage(file=r"D:\food
delivery\assets\Mainwindow\account.png")
account_btn = Button(
menu_bar,
image=account_img,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",

24
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda: accountpage(mainwindow)
)
account_btn.place(
x=877.0,
y=26.25,
width=115.0,
height=32.0
)

mainwindow_canvas = Canvas(mainwindow, bg="#F7F5E6")

scrollbar = Scrollbar(mainwindow, orient="vertical",


command=mainwindow_canvas.yview)
scrollable_frame = Frame(mainwindow_canvas, padx=15, pady=50, bg="#F7F5E6")

mainwindow_canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")


mainwindow_canvas.configure(yscrollcommand=scrollbar.set)
mainwindow_canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")

def update_scrollregion():
scrollable_frame.update_idletasks()
mainwindow_canvas.config(scrollregion=mainwindow_canvas.bbox("all"))

def mouse_scroll_main(event):
mainwindow_canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")

mainwindow_canvas.bind_all("<MouseWheel>", mouse_scroll_main)

def on_mainwindow_focus_in(event):

25
mainwindow_canvas.bind_all("<MouseWheel>", mouse_scroll_main)
if 'restaurantinterface_canvas' in globals():
restaurantinterface_canvas.unbind_all("<MouseWheel>")

mainwindow.bind("<FocusIn>", on_mainwindow_focus_in)

def load_images(image_folder): #function to load all image paths and store in a list

images = []
for img_file in os.listdir(image_folder):
img_path = os.path.join(image_folder, img_file)
images.append(img_path)

display_images_in_grid(images)
update_scrollregion()

def display_images_in_grid(images):
columns = 4
x_spacing = 45
y_spacing = 50

for index, img_path in enumerate(images):


row = (index // columns) + 1
col = (index % columns)
add_image(img_path, row, col, x_spacing, y_spacing)

def add_image(img_path, row, col, x_spacing, y_spacing): #function to place all


restaurant buttons
img = Image.open(img_path)

file_name_with_extension = os.path.basename(img_path)

rest_id, _ = os.path.splitext(file_name_with_extension) #splitting and extracting


rest_id from filename

26
cur.execute("SELECT Restaurant_name FROM Restaurant WHERE
Restaurant_id=%s", (rest_id,))
rec = cur.fetchone()

img.thumbnail((150, 150))
img = ImageTk.PhotoImage(img)

restaurant_btn = Button(scrollable_frame, image=img,


command=lambda:restinterface(rest_id),
borderwidth=0, highlightthickness=0)

restaurant_btn.image = img

restaurant_btn.grid(row=row*2, column=col, padx=45, pady=(0, 10))

restaurant_name = Label(scrollable_frame, text=rec[0], font=("Yu Gothic UI


Semibold", 12), bg="#F7F5E6")
restaurant_name.grid(row=row*2 + 1, column=col, padx=(0, 10), pady=(0, 60))

#folder where restaurant images are saved


#filename of each image is its respective restaurant_id
image_folder_path = r"D:\food delivery\assets\Mainwindow\restaurant pics"
load_images(image_folder_path)

mainwindow.mainloop()

def restinterface(rest_id): #creation of sidebar window with menu items


global Restaurant_Interface

if Restaurant_Interface is not None:


try:
if Restaurant_Interface.winfo_exists():

27
Restaurant_Interface.destroy()
except TclError:
Restaurant_Interface = None

#to check whether user has already added items to cart


cur.execute("select * from cart where user_id=%s",(user_id,))
restcheck=cur.fetchall()

#if added , then deletes those records


#U can only order from one restaurant at a time
if len(restcheck)!=0:
cur.execute("delete from cart where user_id=%s",(user_id,))
cn.commit()

global image_references #To avoid tkinter image garbage collection


image_references = []

cur.execute("SELECT item_id, item_name, price FROM menu WHERE


restaurant_id=%s", (rest_id,))
reststore = cur.fetchall() #fetching records of all items in this particular restaurant

def update_counter(label, count): #function to update cart quantity counter


label.config(text=str(count))

#function which handles '+' cart operations


def add_to_cart(counter_label, count,user_id,rest_id,item_id,item_name,item_price):
count += 1
update_counter(counter_label, count)
current_date = datetime.now().date()

if count==1: #if first time adding , then inserts

record=(user_id,rest_id,current_date,item_id,item_name,count,item_price*count)
cur.execute("Insert into cart values(%s,%s,%s,%s,%s,%s,%s)",(record))
cn.commit()

else: #else updates quantity

28
cur.execute("UPDATE cart SET quantity = %s, price = %s WHERE user_id = %s
AND item_id = %s", (count, item_price * count, user_id, item_id))
cn.commit()

return count

#function which handles '-' cart operations


def remove_from_cart(counter_label,
count,user_id,rest_id,item_id,item_name,item_price):
if count > 0:
count -= 1
if count == 0: #to delete from cart when quantity decremented to 0
cur.execute("DELETE FROM cart WHERE user_id = %s AND item_id = %s",
(user_id, item_id))
cn.commit()

else:
cur.execute("UPDATE cart SET quantity = %s, price = %s WHERE user_id = %s
AND item_id = %s", (count, item_price * count, user_id, item_id))
cn.commit()
update_counter(counter_label, count)
return count

Restaurant_Interface = Toplevel(mainwindow)
Restaurant_Interface.title("Restaurant Interface")
Restaurant_Interface.geometry("310x600")

restaurantinterface_canvas = Canvas(Restaurant_Interface, height=600,


width=310,bg="#F7F5E6")
restaurantinterface_canvas.grid(row=0, column=0, sticky='nsew')

scrollbar = Scrollbar(Restaurant_Interface, orient='vertical',


command=restaurantinterface_canvas.yview)
scrollbar.grid(row=0, column=1, sticky='ns')
restaurantinterface_canvas.configure(yscrollcommand=scrollbar.set)

29
main_frame = Frame(restaurantinterface_canvas,bg="#F7F5E6")
restaurantinterface_canvas.create_window((0, 0), window=main_frame,
anchor='nw')

#stores restname,cuisine,address for display


cur.execute("select restaurant_name,address,cuisine from restaurant where
restaurant_id=%s",(rest_id,))
restdetails=cur.fetchone()
rest_name=restdetails[0]
rest_address=restdetails[1]
rest_cuisine=restdetails[2]

rest_name=Label(main_frame,text=restdetails[0],font=('Nunito',
9,'bold'),fg='#000000', bg='#F7F5E6')
rest_name.grid(row=0,column=0, columnspan=2, sticky='w',padx=10)

rest_cuisine=Label(main_frame,text=restdetails[2],font=('Nunito',
9,'bold'),fg='#000000', bg='#F7F5E6')
rest_cuisine.grid(row=1,column=0, columnspan=2, sticky='w',padx=10)

rest_address=Label(main_frame,text=restdetails[1],font=('Nunito',
9,'bold'),fg='#000000', bg='#F7F5E6')
rest_address.grid(row=2,column=0, columnspan=2, sticky='w',padx=10)

item_frame_path = "D:/food delivery/assets/restinterface/framebox.png"


orange_box_image = "D:/food delivery/assets/restinterface/orangebox.png"
minus_icon_path = "D:/food delivery/assets/restinterface/minus.png"
plus_icon_path = "D:/food delivery/assets/restinterface/plus.png"

item_frame_img = PhotoImage(file=item_frame_path)
orange_img = PhotoImage(file=orange_box_image)

30
minus_img = PhotoImage(file=minus_icon_path)
plus_img = PhotoImage(file=plus_icon_path)

def add_menu_item(frame, row, item_id, item_name, item_price): #function to


display items

#filename of each image is its respective item_id


item_extension = ".png"
item_directory = "D:/food delivery/assets/items/ITEMS/"
item_image_path = os.path.join(item_directory, item_id + item_extension)

item_img = PhotoImage(file=item_image_path)
image_references.append(item_img)

item_frame = Frame(frame, width=290, height=100,bg="#F7F5E6")


item_frame.grid(row=row, column=0, padx=5, pady=10, sticky='nsew')

background_label = Label(item_frame, image=item_frame_img)


background_label.grid(row=0, column=0, rowspan=3, columnspan=3,
sticky='nsew')

image_label = Label(item_frame, image=item_img, borderwidth=0,bg="#FFF7BB")


image_label.grid(row=0, column=2, rowspan=2, sticky='ne', padx=(0, 15),
pady=(18, 0))

Label(item_frame, text=item_name, font=('Instrument Sans', 12,'bold'),fg='#212121',


bg='#FFF7BB').grid(row=0, column=0, sticky='nw', padx=10, pady=10)
Label(item_frame, text="₹"+str(item_price), font=('Instrument Sans', 10,'bold'),
bg='#FFF7BB').grid(row=0, column=0, sticky='nw', padx=10, pady=(32, 0))

31
box_label = Label(item_frame, image=orange_img, borderwidth=0)
box_label.grid(row=1, column=0, columnspan=2, sticky='nw', padx=(10, 0),
pady=0)

counter = IntVar(value=0) #counter variable for quantity counting

counter_label = Label(item_frame, text=str(counter.get()), font=('Instrument Sans',


10,'bold'), bg="#FF8A23", activebackground="#FF8A23", activeforeground="white")
counter_label.grid(row=1, column=0, sticky="w", padx=(40, 0), pady=(0, 8))

minus_button = Button(item_frame, image=minus_img, borderwidth=0,


bg="#FF8A23", activebackground="#FF8A23", activeforeground="white",
command=lambda: counter.set(remove_from_cart(counter_label,
counter.get(),user_id,rest_id,item_id,item_name,item_price)))
minus_button.grid(row=1, column=0, sticky='w', padx=(15, 0), pady=(0, 8))

plus_button = Button(item_frame, image=plus_img, borderwidth=0,


bg="#FF8A23", activebackground="#FF8A23", activeforeground="white",
command=lambda: counter.set(add_to_cart(counter_label,
counter.get(),user_id,rest_id,item_id,item_name,item_price)))
plus_button.grid(row=1, column=0, sticky='w', padx=(65, 0), pady=(0, 8))

for i in range(5): #only 5 items in each restaurant


itemdetails = reststore[i] #retrieving details of each item

item_id = itemdetails[0]
item_name = itemdetails[1]
item_price = itemdetails[2]

add_menu_item(main_frame, i + 4, item_id, item_name, item_price)

main_frame.update_idletasks()

restaurantinterface_canvas.config(scrollregion=restaurantinterface_canvas.bbox("all"))

32
def mouse_scroll_rest(event):
restaurantinterface_canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")

restaurantinterface_canvas.bind_all("<MouseWheel>", mouse_scroll_rest)

def on_restaurant_focus_in(event):

restaurantinterface_canvas.bind_all("<MouseWheel>", mouse_scroll_rest)
if 'mainwindow_canvas' in globals():
mainwindow_canvas.unbind_all("<MouseWheel>")

Restaurant_Interface.bind("<FocusIn>", on_restaurant_focus_in)

Restaurant_Interface.resizable(False, False)
Restaurant_Interface.mainloop()

def cartinterface(mainwindow): #cart window creation


global cart
mainwindow.destroy()
cur.execute("select * from cart where user_id=%s", (user_id,))
cartcheck = cur.fetchall() #checking if cart is empty

if cartcheck: #cart not empty


cur.execute("select distinct restaurant_id from cart where user_id=%s", (user_id,))
restidstore=cur.fetchone()[0]

cart = Tk()
cart.geometry("1012x569")
cart.title("Cart")
cart.configure(bg="#F7F5E6")

cart_canvas = Canvas(
cart,
bg="#F7F5E6",

33
height=569,
width=1012,
bd=0,
highlightthickness=0,
relief="ridge"
)
cart_canvas.pack(fill="both", expand=True)

deliboy_img=PhotoImage(file="D:/food delivery/assets/cart/deliboy.png")
deliboy=cart_canvas.create_image(230.72,90,image=deliboy_img)

boximg=PhotoImage(file="D:/food delivery/assets/cart/box.png")
box=cart_canvas.create_image(819,88.25,image=boximg)

mapimg=PhotoImage(file="D:/food delivery/assets/cart/map.png")
map_icon=cart_canvas.create_image(350,250,image=mapimg)

restimg_extension = ".png"
restimg_directory = "D:/food delivery/assets/Mainwindow/restaurant pics"
rest_image_path = os.path.join(restimg_directory, str(restidstore) +
restimg_extension)

rest_image = Image.open(rest_image_path)
resized_image = rest_image.resize((136, 90), Image.Resampling.LANCZOS)
restimg = ImageTk.PhotoImage(resized_image)
rest_img=cart_canvas.create_image(740,88.25,image=restimg)

cur.execute("select restaurant_name,cuisine from restaurant where


restaurant_id=%s",(restidstore,))
restdisp=cur.fetchone()
restname=restdisp[0]
restcuisine=restdisp[1]

cur.execute("select sum(price) from cart where user_id=%s",(user_id,))


itemstotal=cur.fetchone()[0]
gst=itemstotal*5/100

34
cart_canvas.create_text(
820.1,
50,
anchor="nw",
text=restname,
fill="#000000",
font=("Inter Bold", 15 * -1,'bold')
)

cart_canvas.create_text(
820.1,
75,
anchor="nw",
text=restcuisine,
fill="#000000",
font=("Inter Bold", 13 * -1,'bold')
)

scroll_canvas = Canvas(cart, width=325, height=154, bg="#FFD966",


highlightthickness=0)
scroll_canvas.place(x=657, y=146.25)

scrollframe = Frame(scroll_canvas, bg="#FFD966", width=325, height=154)


scroll_canvas.create_window((0, 0), window=scrollframe, anchor="nw")

scrollframe.bind("<Configure>", lambda e:
scroll_canvas.configure(scrollregion=scroll_canvas.bbox("all")))

def on_mouse_wheel(event):
scroll_canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")

scroll_canvas.bind_all("<MouseWheel>", on_mouse_wheel)

35
cur.execute("select item_name,quantity,price from cart where
user_id=%s",(user_id,))
billstore=cur.fetchall()
lim=len(billstore)

for i in range(0, lim): #displaying items in bill


item=billstore[i][0]
itemlabel = Label(scrollframe, text=item, bg="#FFD966", font=("Arial", 12))
itemlabel.grid(row=i, column=0, padx=(11,0), pady=7,sticky="w")

quantity=billstore[i][1]
quanlabel = Label(scrollframe, text="x"+str(quantity), bg="#FFD966",
font=("Arial", 12))
quanlabel.grid(row=i, column=1, padx=(40,0), pady=7)

price=billstore[i][2]
pricelabel = Label(scrollframe, text="₹"+str(price), bg="#FFD966", font=("Arial",
12))
pricelabel.grid(row=i, column=2, padx=(50,0), pady=7,sticky="e")

bottombox_image = PhotoImage(
file="D:/food delivery/assets/cart/bottombox.png")
bottombox = cart_canvas.create_image(
819.0,
421.25,
image=bottombox_image
)

cart_canvas.create_text(
669.0,
300.25,
anchor="nw",
text="Bill Details\n",
fill="#393939",
font=("RadioCanada Regular", 20 * -1)
)

36
cart_canvas.create_text(
669.0,
327.25,
anchor="nw",
text="Item Total "+str(itemstotal),
fill="#393939",
font=("RadioCanada Regular", 20 * -1)
)

cart_canvas.create_text(
669.0,
354.25,
anchor="nw",
text="Delivery Fee 20",
fill="#393939",
font=("RadioCanada Regular", 20 * -1)
)

cart_canvas.create_text(
669.0,
381.25,
anchor="nw",
text="GST "+str(gst),
fill="#393939",
font=("RadioCanada Regular", 20 * -1)
)
finalbill=itemstotal+20+gst
cart_canvas.create_text(
669.0,
420.25,
anchor="nw",
text="TO PAY "+str(finalbill),
fill="#000000",
font=("RadioCanada Bold", 20 * -1)
)

cod_image = PhotoImage(
file="D:/food delivery/assets/cart/cod.png")
cod = cart_canvas.create_image(

37
815.0,
465.25,
image=cod_image
)

line_image = PhotoImage(
file=("D:/food delivery/assets/cart/line.png"))
line = cart_canvas.create_image(
819.0,
412.75,
image=line_image
)

placeorder_image = PhotoImage(
file="D:/food delivery/assets/cart/placeorder.png")
placeorder = Button(
image=placeorder_image,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda: placeoderfunc(cart),
relief="flat"
)
placeorder.place(
x=739.0,
y=487.25,
width=160.2,
height=40.0
)
homebutton_img = PhotoImage(
file="D:/food delivery/assets/cart/home.png")
homebutton = Button(
image=homebutton_img,
borderwidth=0,
bg='#F7F5E6',
activebackground="#F7F5E6",

38
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda: mainwindowinterface(),
relief="flat"
)
homebutton.place(
x=17.0,
y=16.25,
width=48.0,
height=48.0
)
cur.execute("select address from users where user_id=%s",(user_id,))
cartaddress=cur.fetchone()[0]

cart_canvas.create_text(
440.0,
480.25,
anchor="nw",
text="Delivering To:",
fill="#000000",
font=("RadioCanada Regular", 20 * -1,"bold")
)

cart_canvas.create_text(
390.0,
510.25,
anchor="nw",
text=cartaddress,
fill="#1B1B1B",
font=("RadioCanada Regular", 17 * -1)
)
cart.resizable(False,False)
cart.mainloop()

else: #if cart is empty , displays appropriate msg


cart = Tk()
cart.geometry("1012x569")
cart.title("Cart")

39
cart.configure(bg = "#F7F5E6")

cart_canvas = Canvas(
cart,
bg = "#F7F5E6",
height = 569,
width = 1012,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)

cart_canvas.place(x = 0, y = 0)
chick_img = PhotoImage(
file="D:/food delivery/assets/cart/chick.png")
chick = cart_canvas.create_image(
354.0,
284.25,
image=chick_img
)

urcart_img = PhotoImage(
file="D:/food delivery/assets/cart/urcart.png")
urcart = cart_canvas.create_image(
687.0,
283.25,
image=urcart_img
)

homebutton_img = PhotoImage(
file="D:/food delivery/assets/cart/home.png")
homebutton = Button(
image=homebutton_img,
borderwidth=0,
bg='#F7F5E6',
activebackground="#F7F5E6",
activeforeground="white",
fg="white",

40
highlightthickness=0,
command=lambda: mainwindowinterface(),
relief="flat"
)
homebutton.place(
x=17.0,
y=16.25,
width=48.0,
height=48.0
)

cart.resizable(False, False)
cart.mainloop()

def placeoderfunc(cart): #function of place order button


messagebox.showinfo("Order", "Order Successfully placed.")
cart.destroy()
#removes entry from database when order is succesfull
cur.execute("delete from cart where user_id=%s",(user_id,))
cn.commit()
mainwindowinterface()

def accountpage(mainwindow): #creation of account settings window


mainwindow.destroy()

cur.execute("select username,password,phone_no,address from users where


user_id=%s",(user_id,))
userstore=cur.fetchone() #fethces all account details

#displaying all current details with option to change


global account_setting
account_setting = Tk()
account_setting.title("Account Settings")
account_setting.geometry("1012x569")
account_setting.configure(bg = "#F7F5E6")

account_setting_canvas = Canvas(

41
account_setting,
bg = "#F7F5E6",
height = 569,
width = 1012,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)

account_setting_canvas.place(x = 0, y = 0)
account_setting_box_img = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\login_signup_box.png")
account_setting_box = account_setting_canvas.create_image(
760.7,
284.5,
image=account_setting_box_img
)

account_setting_canvas.create_text(
640.1,
114.3,
anchor="nw",
text="Edit Your Account",
fill="#282727",
font=("IstokWeb Bold", 28* -1,"bold")
)

entry_image_1 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_1 = account_setting_canvas.create_image(
761.1,
195.0,
image=entry_image_1
)
account_setting_username = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0

42
)
account_setting_username.place(
x=638.2,
y=180.0,
width=245.6,
height=30.9
)

account_setting_username.insert(0,userstore[0])

entry_image_2 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_2 = account_setting_canvas.create_image(
761.1,
254.5,
image=entry_image_2
)
account_setting_password = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0,
)
account_setting_password.place(
x=638.2,
y=239.6,
width=245.6,
height=30.9

)
account_setting_password.insert(0,userstore[1])

account_setting_canvas.create_text(
634.6,
159.7,
anchor="nw",
text="Username",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")

43
)

entry_image_3 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_3 = account_setting_canvas.create_image(
761.1,
314.1,
image=entry_image_3
)
account_setting_phoneno = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
account_setting_phoneno.place(
x=638.2,
y=299.1,
width=245.6,
height=30.9
)
account_setting_phoneno.insert(0,userstore[2])

account_setting_canvas.create_text(
634.6,
278.8,
anchor="nw",
text="Phone No",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

entry_image_4 = PhotoImage(
file=r"D:\food delivery\assets\loginsignup\entrybox.png")
entry_bg_4 = account_setting_canvas.create_image(
761.1,
373.7,
image=entry_image_4
)

44
account_setting_address = Entry(
bd=0,
bg="#F7F5E6",
fg="#000716",
highlightthickness=0
)
account_setting_address.place(
x=638.2,
y=358.7,
width=245.6,
height=30.9
)
account_setting_address.insert(0,userstore[3])

account_setting_canvas.create_text(
634.6,
338.3,
anchor="nw",
text="Address",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

account_setting_canvas.create_text(
634.6,
219.2,
anchor="nw",
text="Password",
fill="#000000",
font=("IstokWeb Bold", 12 * -1,"bold")
)

update_img = PhotoImage(
file=r"D:\food delivery\assets\account setting\update.png")
update_button = Button(
image=update_img,
borderwidth=0,
bg='#FFD966',
activebackground="#FFD966",

45
activeforeground="white",
fg="white",
highlightthickness=0,
command=lambda:
accountsetting_validate(account_setting,account_setting_username,account_setting_
password,
account_setting_phoneno,account_setting_address),
relief="flat"
)
update_button.place(
x=680.9,
y=416.3,
width=160.2,
height=40.0
)

pan_img1 = PhotoImage(file=r"D:\food delivery\assets\loginsignup\pan.png")


pan1 = account_setting_canvas.create_image(
215.0,
295.9,
image=pan_img1
)

egg_img1 = PhotoImage(file=r"D:\food delivery\assets\loginsignup\egg.png")


egg1 = account_setting_canvas.create_image(
345.0,
280.9,
image=egg_img1
)

homebutton_img = PhotoImage(
file="D:/food delivery/assets/cart/home.png")
homebutton = Button(
image=homebutton_img,
borderwidth=0,
bg='#F7F5E6',
activebackground="#F7F5E6",
activeforeground="white",

46
fg="white",
highlightthickness=0,
command=lambda: mainwindowinterface(),
relief="flat"
)
homebutton.place(
x=17.0,
y=16.25,
width=48.0,
height=48.0
)

account_setting.resizable(False, False)

account_setting.mainloop()

#function to check if entered details are valid


def
accountsetting_validate(account_setting,account_setting_username,account_setting_
password,
account_setting_phoneno,account_setting_address):

accountsettingflag=False

entered_username = account_setting_username.get()
entered_password = account_setting_password.get()
entered_phoneno = account_setting_phoneno.get()
entered_address = account_setting_address.get()

cur.execute("SELECT username FROM users where user_id!=%s",(user_id,))


usernamevalidate = cur.fetchall()

if (entered_username,) in usernamevalidate:
messagebox.showerror("Error", "Username already Taken")
elif entered_username=='':
messagebox.showerror("Error", "Please enter a username")
elif entered_password=='':

47
messagebox.showerror("Error", "Please enter a password")

elif entered_phoneno=='' or not entered_phoneno.isdigit() or


len(entered_phoneno)!=10:
messagebox.showerror("Error", "Invalid phoneno")

elif entered_address=='':
messagebox.showerror("Error", "Please enter an address")

else:
accountsettingflag=True

if accountsettingflag==True: #updates new details into database


cur.execute("update users set
username=%s,password=%s,phone_no=%s,address=%s where
user_id=%s",(entered_username,entered_password,entered_phoneno,entered_addres
s,user_id))
cn.commit()
messagebox.showinfo("Account Settings", "Details updated")

databasecreate()
login_func()

48
OUTPUT
Login

Login Error

49
Signup

Account Settings

50
Homepage

Restaurant Interface

51
Bill

Empty Cart

52
BIBLIOGRAPHY

1. https://www.geeksforgeeks.org/python-gui-tkinter/
2. https://realpython.com/python-gui-tkinter/
3. https://github.com/
4. https://www.w3schools.com/python/python_mysql_getstarted.asp
5. https://www.swiggy.com/

53

You might also like