Professional Documents
Culture Documents
Nikhil Project
Nikhil Project
Nikhil Project
RAILWAY RESERVATION
SUBMITTED BY
NIKHIL SHIBU
REG.NO:
CERTIFICATE
Certified that this is the bona-fide record of project work in Computer Science
Principal
Date:
Thottumughom
ACKNOWLEDGEMENT
We are grateful to almighty for giving us the strength to successfully
complete our project and for sustaining our efforts. We very proudly
render our grateful thanks to our manager, Srimath
Dharmachaithanya and our Principal, Mrs. Sumina Subin, for giving
us an opportunity to do this project & also for providing the facilities
to complete it.
We proudly render our thanks to our class teacher, Mrs. Steju Pramod,
for her encouragement and support. We wish to acknowledge our
cordial thanks and deep sense of gratitude to our parents and
guardians, to the authors and publishers of the books and the
managements of the websites we referred to (as in Bibliography) and
various individuals who helped directly or indirectly in completing this
project successfully.
Signature
Nikhil shibu
Sl.No Contents Page No
1. Introduction
2. Objective
4.
Theoretical Background
5.
System Implementation
7. Source Code
8. Screencasts
9. Bibliography
INTRODUCTION
User :
▪ Buy products
Admin :
▪ Add products
▪ Delete items
▪ Update items
OBJECTIVE AND
SCOPE OF THE PROJECT
This project has been developed with the aim of providing a platform
for the user to buy products online and for the admins to update the
information with ease.
o Purchase items
o Add items
o Delete items
o Update items
THEORITICAL BACKGROUND
Python 3.9.10
Python is an interpreted, high-level, general-purpose programming
language. Created by Guido van Rossum and first released in 1991,
Python's design philosophy emphasizes code readability with its notable
use of significant whitespace. Its language constructs and object-oriented
approach aim to help programmers write clear, logical code for small and
large-scale projects. Python is dynamically typed and garbage-collected. It
supports multiple programming paradigms, including procedural, object-
oriented, and functional programming. Python is often described as a
"batteries included" language due to its comprehensive standard library.
Python was conceived in the late 1980s as a successor to the ABC language.
Python 2.0, released in 2000, introduced features like list
comprehensions and a garbage collection system capable of collecting
reference cycles. Python 3.0, released in 2008, was a major revision of the
language that is not completely backward-compatible, and much Python
2 code does not run unmodified on Python 3. Due to concern about the
amount of code written for Python 2, support for Python 2.7 (the last
release in the 2.x series) was extended to 2020. Language developer Guido
van Rossum shouldered sole responsibility for the project until July 2018
but now shares his leadership as a member of a five-person steering
council. The Python 2 language, i.e. Python 2.7.x, is "sunsetting" on
January 1, 2020, and the Python team of volunteers will not fix security
issues or improve it in other ways after that date. With the end-of-life, only
Python 3.5.x and later will be supported. Python interpreters are available
for many operating systems. A global community of programmers
develops and maintains CPython, an open source reference
implementation. A non-profit organization, the Python Software
To find and retrieve just the data that meets conditions you specify,
including data
from multiple tables, create a query. A query can also update or delete
multiple
To find and retrieve just the data that meets conditions you specify,
including data from multiple tables, create a query. A query can also
update or delete multiple records at the same time, and perform built-
in or custom calculations on your data.
MySQL version 8.0
Modules used :
• Mysql.connector
• Tkinter
• Pil
Tables used :
SOURCE CODE
from tkinter import *
from tkinter import ttk
import mysql.connector as sql
from tkinter import messagebox
from PIL import ImageTk,Image
con=sql.connect(host="localhost",user="root",passwd="root",database
="skart")
def Clear_signup():
global u1,p1
u1.delete(0,"end")
p1.delete(0,"end")
def Back_signup():
global root
s=root
s.destroy()
main()
def Submit_signup():
global con,u1,p1,root
con=sql.connect(host="localhost",user="root",passwd="root",database
="skart")
if con.is_connected():
cur=con.cursor()
cur.execute("select * from user where username='{}' and
password='{}'".format(u1.get(),p1.get()))
data1=cur.fetchall()
if len(data1)!=0:
messagebox.showerror("showerror", " username & password
alreday exists...Try Again")
s=root
s.destroy()
main()
else:
cur.execute("select max(id) from user;")
max_id=cur.fetchone()
n=max_id[0]
cur.execute("insert into user
values({},'{}','{}')".format(n+1,u1.get(),p1.get()))
con.commit()
messagebox.showinfo("Success", " Signup Success Login Now
!")
s=root
s.destroy()
main()
def delete_row():
global tree1,r,l2
selected_item=tree1.selection()[0]
item = tree1.item(selected_item)
record = item['values']
records.remove(record)
r=int(r)
r-=record[2]
l2.configure(text=str(r))
tree1.delete(selected_item)
def purchase():
v="Purchase of rupees : "+str(r)+" was successful"
messagebox.showinfo("",v)
homepage()
def sum_price(n):
global a
a+=n[2]
return a
def item_selected():
global tree,tree1,r,l2,records,n1
for selected_item in tree.selection():
print(r)
item = tree.item(selected_item)
record = item['values']
records.append(record)
print(records)
r=sum_price(record)
r=str(r)
l2.configure(text=r)
tree1.insert('',n1+1,text='',values=(record[0],record[1],record[2],record
[3]))
n1=0
def homepage():
global root,con,tree,l2,tree1,records,r,a
s=root
s.destroy()
root=Tk()
root.geometry("1225x800")
root.configure(bg="#fff")
root.title("Home page")
r=0
records=[]
a=0
n1=0
img=Image.open("My project-1.png")
myimg=ImageTk.PhotoImage(img)
imglabel=Label(root,image=myimg,bg="white")
imglabel.place(x=0,y=0)
frame=Frame(root,width=850,height=500,bg="white")
frame.place(x=250,y=175)
#ITEM DISPLAY
s=ttk.Style(frame)
s.theme_use("alt")
cur=con.cursor()
cur.execute("select * from item")
tree=ttk.Treeview(frame)
tree.column("Item no",width=200,minwidth=100,anchor=CENTER)
tree.column("Item
name",width=200,minwidth=100,anchor=CENTER)
tree.column("Price",width=200,minwidth=100,anchor=CENTER)
tree.column("Quantity",width=200,minwidth=100,anchor=CENTER)
tree["show"]="headings"
i=0
for n in cur:
tree.insert('',i,text='',values=(n[0],n[1],n[2],n[3]))
i+=1
tree.place(x=0,y=10)
s.configure("Treeview",font=("MicrosoftYaheiUI ight",10),border=0)
tree1=ttk.Treeview(root)
tree1["columns"]=("Item","Qty")
tree1.column("Item",width=200,minwidth=100,anchor=CENTER)
tree1.column("Qty",width=200,minwidth=100,anchor=CENTER)
tree1.heading("Item",text="Item name",anchor=CENTER)
tree1.heading("Qty",text="Quantity",anchor=CENTER)
tree1["show"]="headings"
tree1.place(x=250,y=500)
l1=Label(root,text="Total :",bg="white",fg="black",font=("Microsoft
Yahei UI Light",40,"bold")).place(x=900,y=500)
l2=Label(root,text="0",bg="white",fg="black",font=("Microsoft
Yahei UI Light",30,"bold"))
b=Button(root,text="Select
Item",bg="#fff",fg="blue",font=("Microsoft Yahei UI
Light",15,"bold"),border=0,command=lambda:item_selected()).place(x
=1000,y=410)
b1=Button(root,text="Purchase",bg="#fff",fg="blue",font=("Microsoft
Yahei UI
Light",20,"bold"),border=0,command=lambda:purchase()).place(x=100
0,y=610)
b=Button(root,text="Delete
Item",bg="#fff",fg="blue",font=("Microsoft Yahei UI
Light",15,"bold"),border=0,command=lambda:delete_row()).place(x=7
00,y=610)
l2.place(x=1100,y=510)
root.mainloop()
def signup():#New user Sign up
global root,con,u1,p1
s=root
s.destroy()
root=Tk()
root.geometry('1920x1080')
root.title("Signup Page")
root.title("Sign up")
img=Image.open("sign up.png")
myimg=ImageTk.PhotoImage(img)
imglabel=Label(image=myimg)
imglabel.place(x=0,y=0)
frame1=Frame(root,width=250,height=2,bg="black")
frame1.place(x=345,y=295)
frame2=Frame(root,width=250,height=2,bg="black")
frame2.place(x=345,y=355)
def modify_product():
global root,con,itb_m,prb_m,qtyb_m
s=root
s.destroy()
root=Tk()
root.geometry("1225x800")
root.configure(bg="#fff")
root.title("Modify")
img2=Image.open("modify-1.png")
myimg2=ImageTk.PhotoImage(img2)
imglabel2=Label(root,image=myimg2,bg="white")
imglabel2.place(x=0,y=0)
it=Label(root,text = "Item
name",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=300)
pr=Label(root,text =
"Price",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=350)
qty=Label(root,text =
"Quantity",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=400)
frame1=Frame(root,width=275,height=2,bg="black")
frame1.place(x=400,y=330)
frame2=Frame(root,width=275,height=2,bg="black")
frame2.place(x=400,y=380)
frame3=Frame(root,width=275,height=2,bg="black")
frame3.place(x=400,y=430)
itb_m=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
itb_m.place(x=400,y=300)
prb_m=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
prb_m.place(x=400,y=350)
qtyb_m=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
qtyb_m.place(x=400,y=400)
mod=Button(root,text="Modify",bg="#fff",fg="black",border=0,width=
15,font=("Microsoft Yahei UI
Light",15),command=lambda:modify()).place (x=550,y=500)
bac=Button(root,text="BACK",bg="#fff",fg="black",border=0,width=1
5,font=("Microsoft Yahei UI Light",15),command=lambda:
back()).place (x=700,y=500)
root.mainloop()
def delete_product():
global root,con,itb_d,prb_d,qtyb_d,tree3
s=root
s.destroy()
root=Tk()
root.geometry("1225x800")
root.configure(bg="#fff")
root.title("Delete")
img2=Image.open("delete-1.png")
myimg2=ImageTk.PhotoImage(img2)
imglabel2=Label(root,image=myimg2,bg="white")
imglabel2.place(x=0,y=0)
cur=con.cursor()
cur.execute("select * from item")
tree3=ttk.Treeview(root)
tree3.column("Item
no",width=200,minwidth=100,anchor=CENTER)
tree3.column("Item
name",width=200,minwidth=100,anchor=CENTER)
tree3.column("Price",width=200,minwidth=100,anchor=CENTER)
tree3.column("Quantity",width=200,minwidth=100,anchor=CENTER
)
tree3["show"]="headings"
i=0
for n in cur:
tree3.insert('',i,text='',values=(n[0],n[1],n[2],n[3]))
i+=1
tree3.place(x=200,y=200)
de1=Button(root,text="Delete",bg="#fff",fg="black",border=0,width=1
5,font=("Microsoft Yahei UI
Light",15),command=lambda:delete()).place (x=700,y=450)
bac=Button(root,text="BACK",bg="#fff",fg="black",border=0,width=1
5,font=("Microsoft Yahei UI Light",15),command=lambda:
back()).place (x=850,y=450)
root.mainloop()
def admin_page1():
global root,con,itb,prb,qtyb
s=root
s.destroy()
root=Tk()
root.geometry("1225x800")
root.configure(bg="#fff")
root.title("Admin")
img2=Image.open("admin-1.png")
myimg2=ImageTk.PhotoImage(img2)
imglabel2=Label(root,image=myimg2,bg="white")
imglabel2.place(x=0,y=0)
it=Label(root,text = "Item
name",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=300)
pr=Label(root,text =
"Price",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=350)
qty=Label(root,text =
"Quantity",width=15,bg="#fff",fg="black",font=("Microsoft Yahei UI
Light",15)). place(x=200,y=400)
frame1=Frame(root,width=275,height=2,bg="black")
frame1.place(x=400,y=330)
frame2=Frame(root,width=275,height=2,bg="black")
frame2.place(x=400,y=380)
frame3=Frame(root,width=275,height=2,bg="black")
frame3.place(x=400,y=430)
itb=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
itb.place(x=400,y=300)
prb=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
prb.place(x=400,y=350)
qtyb=Entry(root,width=40,border=0,font=("Microsoft Yahei UI
Light",15))
qtyb.place(x=400,y=400)
de1=Button(root,text="Delete",bg="#fff",fg="black",border=0,font=("
Microsoft Yahei UI
Light",15),width=10,command=lambda:delete_product()).place
(x=500,y=500)
add=Button(root,text="Add",bg="#fff",fg="black",border=0,font=("Mic
rosoft Yahei UI Light",15),width=10,command=lambda:
add_product()).place (x=680,y=400)
mod=Button(root,text="Modify",bg="#fff",fg="black",border=0,font=("
Microsoft Yahei UI Light",15),width=10,command=lambda:
modify_product()).place (x=600,y=500)
root.mainloop()
def clr_a():
itb.delete(0,"end")
prb.delete(0,"end")
qtyb.delete(0,"end")
def add_product():
global con,root,itb,prb,qtyb
cur=con.cursor()
cur.execute("select max(item_no) from item")
n=cur.fetchone()
n=n[0]
cur.execute("insert into item values
({},'{}',{},'{}')".format(n+1,str(itb.get()),int(prb.get()),str(qtyb.get())))
con.commit()
messagebox.showinfo("Success")
clr_a()
def clr_d():
itb_d.delete(0,"end")
prb_d.delete(0,"end")
qtyb_d.delete(0,"end")
def delete():
global con,root,itb,prb,qtyb,tree3
cur=con.cursor()
selected_item=tree3.selection()[0]
item = tree3.item(selected_item)
val = item['values']
a=val[1]
print(a,val)
cur.execute("delete from item where item.item='{}'".format(str(a)))
con.commit()
tree3.delete(selected_item)
def modify():
global con,root,itb_m,prb_m,qtyb_m
cur=con.cursor()
cur.execute("select * from item where item='{}'".format(itb_m.get()))
m=cur.fetchall()
if len(m)==0:
messagebox.showinfo("","INVALID")
clr_m()
else:
b=prb_m.get()
c=qtyb_m.get()
if int(m[0][2])!=int(b):
cur.execute("update item set price={} where
item='{}'".format(b,itb_m.get()))
con.commit()
if str(m[0][3])!=str(c):
cur.execute("update item set qty='{}' where
item='{}'".format(c,itb_m.get()))
con.commit()
messagebox.showinfo("","Update successful")
else:
messagebox.showinfo("","Update successful")
elif str(m[0][3])!=str(c):
cur.execute("update item set qty='{}' where
item='{}'".format(c,itb.get()))
con.commit()
messagebox.showinfo("","Update successful")
elif int(m[0][2])==int(b) and str(m[0][3])==str(c):
messagebox.showinfo("","Nothing to update")
clr_m
def admin():
global con,u,p
if con.is_connected():
cur=con.cursor()
cur.execute("select * from admin;")
data=cur.fetchall()
s1=u.get()
s2=p.get()
for i in data:
if s1 in i and s2 in i:
admin_page1()
break
else:
messagebox.showerror("showerror", "Invalid Username and
Password ...Try Again or Sign Up")
else:
messagebox.showerror("showerror", "Connection not success!")
def login():
global con,u,p
if con.is_connected():
cur=con.cursor()
cur.execute("select * from user;")
data=cur.fetchall()
s1=u.get()
s2=p.get()
for i in data:
if s1 in i and s2 in i:
messagebox.showinfo("Success", " Login Success !")
homepage()
break
else:
messagebox.showerror("showerror", "Invalid Username and
Password ...Try Again or Sign Up")
else:
messagebox.showerror("showerror", "Connection not success!")
def on_entry(root):
u.delete(0,'end')
def on_leave(root):
name=u.get()
if name=='':
u.insert(0,'Username')
def on_entry1(root):
p.delete(0,'end')
def on_leave1(root):
name=p.get()
if name=='':
p.insert(0,'Password')
def check():
global v1
a=v1.get()
if a==1:
admin()
if a==0:
login()
def main():
global root ,u,p,v1
root=Tk()
root.geometry('1225x800')
root.configure(bg="#fff")
root.title("sign up/ login ")
img=Image.open("login.png")
myimg=ImageTk.PhotoImage(img)
imglabel=Label(root,image=myimg,bg="white")
imglabel.place(x=0,y=100)
frame=Frame(root,width=450,height=450,bg="white")
frame.place(x=680,y=200)
frame1=Frame(frame,width=275,height=2,bg="black")
frame1.place(x=95,y=175)
frame2=Frame(frame,width=275,height=2,bg="black")
frame2.place(x=95,y=125)
v1=IntVar()
heading=Label(frame,text="Sign
in",fg="#57a1f8",bg="white",font=("Microsoft Yahei UI
Light",23,"bold")).place(x=100,y=5)
u= Entry(frame,width = 30,border=0,font=("Microsoft Yahei UI
Light",11))
u.place(x = 100,y = 100)
u.insert(0,"Username")
u.bind("<FocusIn>",on_entry)
u.bind("<FocusOut>",on_leave)
p= Entry(frame,width = 30,border=0,font=("Microsoft Yahei UI
Light",11))
p.place(x = 100,y = 150)
p.insert(0,"Password")
p.bind("<FocusIn>",on_entry1)
p.bind("<FocusOut>",on_leave1)
s1 = Button(frame,text = "Login",bg="#fff",
width=10,border=0,font=("Microsoft Yahei UI
Light",11),fg="#57a1f8",command=lambda:check()).place(x=100,y =
200)
s2= Button(frame,text = "SignUp",bg="#fff",
width=10,border=0,font=("Microsoft Yahei UI
Light",11),fg="#57a1f8",command=lambda:signup()).place(x = 175,y =
200)
s3 = Radiobutton(frame,text =
"Admin",fg="black",bg="#fff",font=("Microsoft Yahei UI
Light",11),width=5,variable=v1,value=1)
s3.place(x = 120,y = 240)
root.mainloop()
records=[]
a=0
main()
SCREENCAST
BIBLIOGRAPHY
• www.wikipedia.org
• stackoverflow.com
• docs.python.org/2/library/tkinter.html
• www.python.org
• www.mysql.com