Documente Academic
Documente Profesional
Documente Cultură
Detail=['','']
Signup=['','','','']
buytick=['','','','']
tickcancel=['','']
fairlist=['','','']
root=Tk()
root.geometry('888x500+300+100')
root.resizable(False, False)
root.title('RAILWAYS')
bill=0
tea=0
coff=0
L=0
mL=0
VegBk=0
NBk=0
Vmeal=0
Nmeal=0
root.iconbitmap('icon.ico')
#__________________vars for tickets_________________
clas = StringVar()
dest = StringVar()
fr = StringVar()
dt = StringVar()
tickprice=0
#_____________________________________________________logged_______________________
_________________________________
logged=False
#___________________
tname=''
#__________________________________________________________________________________
________________________________
#__________________________________________________________________________________
________________________________
def Main():
global root, logged
for widget in root.winfo_children():
widget.destroy()
train_image=ImageTk.PhotoImage(Image.open('bgtrain.png'))
tlabel=Label(image=train_image)
tlabel.place(x=-2,y=-2)
if not logged:
sign_up=Button(root, text='Sign Up', font=("bold", 10), padx=25, pady=0.8,
bg='light blue', command=signup)
sign_up.place(x=630,y=450)
#__________________________________________________________________________________
________________________________
#__________________________________________________________________________________
________________________________
def Ticket():
global root, dest, fr, dt, tickprice
for widget in root.winfo_children():
widget.destroy()
clas = StringVar()
dest = StringVar()
fr = StringVar()
dt = StringVar()
seats=IntVar()
price=0
train_image=ImageTk.PhotoImage(Image.open('bgtick.png'))
tlabel=Label(image=train_image)
tlabel.place(x=-2,y=-2)
#__________________________________________________________________________________
___________________________________
#__________________________________________________________________________________
___________________________________
def Show():
d=dt.get().split('-')
rd=''
try:
for i in d:
rd+=i
rd=int(rd)
if len(str(rd))>=6 and len(str(rd))<=8:
Date.config(fg='black')
buytick[2]=dt.get()
else:
akdsfh
except:
Date.delete(0, END)
Date.config(fg='red')
Date.insert(0,'Enter Date')
def confirmation():
global tname, logged
try:
if seats.get()=='' or seats.get()==0 or tname=='':
if seats.get()=='' or seats.get()==0:
Enter.config(fg='red')
Enter.delete(0,END)
Enter.insert(0, 'Enter correct seats')
if tname=='':
Label(root, text=' '*100,
font=(20)).place(x=100,y=103)
Label(root, text='Select a Train', fg='red',
font=('bold', 20)).place(x=150,y=100)
else:
for widget in root.winfo_children():
widget.destroy()
seat=random.randint(1,500)
l=seat
if seats.get()>1:
l=seat+seats.get()-1
db=c.connect(host='localhost',user='root',passwd='123456',database='rail')
cur=db.cursor()
cur.execute("update trains set seats=seats-{} where
tname='{}'".format(seats.get(),tname))
if logged:
cur.execute("update email set pnr='{}' where
mail='{}'".format(key,Signup[1]))
cur.execute("insert into buyed
values('{}','{}','{}','{}','{}-{}',
{},'{}')".format(buytick[0],buytick[1],buytick[2],buytick[3],seat,l,key,tname))
cur.execute("select train_no from trains where
tname='{}'".format(tname))
x=cur.fetchone()
Label(root, text='Your PNR : {}\nYour Train name :
{}\nSeats :{}-{}\nTrain Number : {}'.format(key,tname,seat,l,x[0]),
font=('bold',14)).place(x=280,y=200)
db.commit()
Main1=Button(root, text='◄', font=("bold", 10), padx=15,
pady=5, bg='light blue', command=Ticket)
Main1.place(x=0,y=0)
except:
Enter.config(fg='red')
Enter.delete(0,END)
Enter.insert(0, 'Enter correct seats')
raise
db=c.connect(host='localhost',user='root',passwd='123456',database='rail')
cur=db.cursor()
cur.execute("select tname,price from TRAINS")
tlist=cur.fetchall()
db.commit()
Button(root, text='1)'+tlist[0][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[0][1],tlist[0][0])).place(x=10,y=200)
Button(root, text='2)'+tlist[1][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[1][1],tlist[1][0])).place(x=10,y=250)
Button(root, text='3)'+tlist[2][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[2][1],tlist[2][0])).place(x=10,y=300)
Button(root, text='4)'+tlist[3][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[3][1],tlist[3][0])).place(x=10,y=350)
Button(root, text='5)'+tlist[4][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[4][1],tlist[4][0])).place(x=10,y=400)
Button(root, text='6)'+tlist[5][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[5][1],tlist[5][0])).place(x=300,y=200)
Button(root, text='7)'+tlist[6][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[6][1],tlist[6][0])).place(x=300,y=250)
Button(root, text='8)'+tlist[7][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[7][1],tlist[7][0])).place(x=300,y=300)
Button(root, text='9)'+tlist[8][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[8][1],tlist[8][0])).place(x=300,y=350)
Button(root, text='10)'+tlist[9][0], font=('bold',14), borderwidth=0,
command=lambda:Setprice(tlist[9][1],tlist[9][0])).place(x=300,y=400)
Label(root, text='Available Trains',
font=('bold',14)).place(x=175,y=170)
#_________________________________________NEXT_____________________________________
__________________
Next=Button(root, text='Next', font=('bold',14),
command=confirmation).place(x=610,y=300)
#_________________________________________BACK_____________________________________
__________________
Main1=Button(root, text='◄', font=("bold", 10), padx=15, pady=5,
bg='light blue', command=Ticket)
Main1.place(x=0,y=0)
print(buytick,key,tickprice)
root.mainloop()
#__________________________________________________________________________________
__________________________________
#__________________________________________________________________________________
___________________________________
def Cancel():
for widget in root.winfo_children():
widget.destroy()
#______________________
def Show():
if cpnr.get()==0:
Label(root, text='Enter PNR!!', font=("bold", 10),
fg='red').place(x=570, y=100)
else:
tickcancel[0]=cpnr.get()
Label(root, text=' '*18, font=("bold", 10),
fg='red').place(x=570, y=100)
if tno.get()=='':
Label(root, text='Enter Train No.!!', font=("bold", 10),
fg='red').place(x=560, y=150)
else:
tickcancel[1]=tno.get()
Label(root, text=' '*18, font=("bold", 10),
fg='red').place(x=560, y=150)
db=c.connect(host='localhost',user='root',passwd='123456',database='rail')
cur=db.cursor()
cur.execute("select seatno,tno from buyed where
pnr={}".format(cpnr.get()))
vals=cur.fetchone()
x=eval(vals[0])-1
cur.execute("update trains set seats=seats-{} where
tname='{}'".format(x,vals[1]))
cur.execute("delete from buyed where
pnr={}".format(cpnr.get()))
db.commit()
Label(root, text='Cancellation Confirmed!', font=("bold",
14)).place(x=278,y=250)
except:
Label(root, text='Only Digits', font=("bold", 14),
fg='red').place(x=650,y=100)
print(tickcancel)
raise
SUB.config(state='disabled')
#______________________
cpnr = IntVar()
tno = StringVar()
root.mainloop()
#_______________________________________
def PNR():
for widget in root.winfo_children():
widget.destroy()
def pnrc():
try:
if code.get()!= 0:
db=c.connect(host='localhost',user='root',passwd='123456',database='rail')
cur=db.cursor()
cur.execute("select PNR from buyed where
PNR='{}'".format(code.get()))
if code.get()==cur.fetchone()[0]:
Label(root, text=' '*10).place(x=650,y=105)
Label(root, text='TICKET CONFIRMED!', font=("bold",
14)).place(x=278,y=250)
else:
Label(root, text='TICKET NOT CONFIRMED!', font=("bold",
14)).place(x=278,y=250)
SUB.config(state='disabled')
db.commit()
else:
Label(root, text='Enter PNR', font=("bold", 14),
fg='red').place(x=650,y=100)
except (c.errors.InterfaceError,TypeError):
Label(root, text=' '*10).place(x=650,y=105)
Label(root, text='TICKET NOT CONFIRMED!', font=("bold",
14)).place(x=278,y=250)
except:
Label(root, text='Only Digits', font=("bold", 14),
fg='red').place(x=650,y=100)
raise
code=IntVar()
Label(root, text='Enter PNR Code', font=("bold", 14), padx=50,
pady=5).place(x=150,y=100)
e1=Entry(root, textvariable=code, borderwidth=5, font=("bold", 10))
e1.place(x=480,y=100)
#_______________________________________
def fair():
for widget in root.winfo_children():
widget.destroy()
d=StringVar()
f=StringVar()
c=StringVar()
def show():
#if len(fairlist)!=3:
if d.get()=='':
Label(root, text='Enter Destination!!', font=("bold", 10),
fg='red').place(x=570, y=100)
else:
fairlist[0]=d.get()
Label(root, text=' '*18, font=("bold", 10),
fg='red').place(x=570, y=100)
if f.get()=='':
Label(root, text='Enter Source Station!!', font=("bold", 10),
fg='red').place(x=560, y=150)
else:
fairlist[1]=f.get()
Label(root, text=' '*18, font=("bold", 10),
fg='red').place(x=560, y=150)
if c.get()=='':
Label(root, text='Select Seats!!', font=("bold", 10),
fg='red').place(x=580, y=200)
else:
fairlist[2]=c.get()
Label(root, text=' ', width=10, font=("bold", 10),
fg='red').place(x=580, y=200)
x=0
for i in range(3):
if fairlist[i]=='':
x=1
else:
x=0
if x==0 and fairlist!=[]:
print(fairlist)
SUB.config(state='disabled')
clas=StringVar()
e1=Entry(root, textvariable=d, borderwidth=5, font=("bold", 10))
e1.place(x=400,y=100)
e2=Entry(root, textvariable=f, borderwidth=5, font=("bold", 10))
e2.place(x=400,y=150)
o=OptionMenu(root, c, 'Second Class', 'Third AC', 'Second AC' ,'First AC')
o.place(x=400,y=200)
Class=OptionMenu(f, clas, 'Second Class', 'Third AC', 'Second AC' ,'First AC')
Class.grid(row=6,column=0)
Label(f, bg='white').grid(row=7,column=0)
SUB=Button(f, text='Find Trains', font=("bold", 10), bg='SystemButtonFace',
command=Show)
SUB.grid(row=8,column=0)
#Label(x).grid(row=0,column=0)
# to main
Main1=Button(root, text='◄', font=("bold", 10), padx=15, pady=5, bg='light
blue', command=Main)
Main1.place(x=0,y=0)
# Refresh
refresh=Button(root, text='⟲', font=("bold", 10), bg='light blue', padx=10,
pady=5, command=Ticket)
refresh.place(x=847,y=0)
root.mainloop()
#__________________________________________________________________________________
________________________________
#__________________________________________________________________________________
________________________________
def train():
global root
for widget in root.winfo_children():
widget.destroy()
Tno=IntVar()
Detail=['','']
def show():
try:
print(Tno.get())
if Tno.get()/1000<1:
e1.delete(0, END)
e1.config(fg='red')
e1.insert(0,'Enter 4-Digits!!')
else:
Detail[0]=Tno.get()
e1.config(fg='black')
if Detail[0]=='':
pass
else:
try:
db=c.connect(host='localhost', user='root',passwd='123456',
database='rail')
cur=db.cursor()
cur.execute("select * from trains where
train_no='{}'".format(Detail[0]))
vals=cur.fetchone()
Label(x, text='Your Train name : {}\nTrain Number : {}\nSeats :
{}'.format(vals[0],vals[1],vals[3]), bg='white',
font=('bold',10)).grid(row=2,column=1)
except TypeError:
e1.delete(0, END)
e1.config(fg='red')
e1.insert(0,'Incorrect Train number')
except:
e1.delete(0, END)
e1.config(fg='red')
e1.insert(0,'Only Digits!!')
raise
train_image=ImageTk.PhotoImage(Image.open('bginfo.png'))
tlabel=Label(image=train_image)
tlabel.place(x=-2,y=-2)
# Refresh
refresh=Button(root, text='⟲', font=("bold", 10), bg='light blue', padx=10,
pady=5, command=train)
refresh.place(x=847,y=0)
root.mainloop()
#__________________________________________________________________________________
________________________________
#__________________________________________________________________________________
________________________________
def Food():
global root, bill
for widget in root.winfo_children():
widget.destroy()
def zero():
global bill, tea, coff, L, mL, VegBk, NBk, Vmeal, Nmeal
bill=0
tea=0
coff=0
L=0
mL=0
VegBk=0
NBk=0
Vmeal=0
Nmeal=0
Food()
def Total(x):
global bill, tea, coff, L, mL, VegBk, NBk, Vmeal, Nmeal
if x==7 or x==-7:
if x>0:
tea+=1
elif bill*tea!=0:
tea-=1
if bill+x>=0:
bill+=x
# Confirm Order______________
def confirm():
global root
if bill>0:
for widget in root.winfo_children():
widget.destroy()
tn=IntVar()
sn=IntVar()
def done():
try:
if tn.get()!= 0:
Label(root, text=' '*10).place(x=650,y=165)
else:
Label(root, text='Enter Train No.', font=("bold", 14),
fg='red').place(x=650,y=158)
except:
Label(root, text=' '*10).place(x=650,y=165)
Label(root, text='Only Digits', font=("bold", 14),
fg='red').place(x=650,y=158)
#====================================================================
try:
if sn.get()!= 0:
Label(root, text=' '*10).place(x=650,y=245)
else:
Label(root, text='Enter Seat No.', font=("bold", 14),
fg='red').place(x=650,y=238)
except:
Label(root, text=' '*10).place(x=650,y=245)
Label(root, text='Only Digits', font=("bold", 14),
fg='red').place(x=650,y=238)
#====================================================================
try:
if tn.get()!=0 and sn.get()!=0:
e1.config(state='disabled')
e2.config(state='disabled')
Label(root, text='CONFIRMED!', font=("bold",
16)).place(x=380,y=350)
except:
pass
FOOD=ImageTk.PhotoImage(Image.open('menu.png'))
label1=Label(image=FOOD)
label1.place(x=0,y=0)
# Refresh
refresh=Button(root, text='⟲', font=("bold", 10), bg='light blue', padx=10,
pady=5, command=zero)
refresh.place(x=847,y=0)
Total(0)
root.mainloop()
#__________________________________________________________________________________
__________________________________
#__________________________________________________________________________________
__________________________________
def signup():
global root
for widget in root.winfo_children():
widget.destroy()
def Add_account():
global logged
if Gender.get()==1:
Signup[3]='Male'
elif Gender.get()==2:
Signup[3]='Female'
else:
pass
if name.get()=='':
Label(root, text='Enter Name!!', font=("bold", 10),
fg='red').place(x=560, y=130)
else:
Signup[0]=name.get()
Label(root, text=' '*18, font=("bold", 10), fg='red').place(x=560,
y=130)
if mail.get()=='':
Label(root, text='Enter Email!!', font=("bold", 10),
fg='red').place(x=560, y=180)
else:
Signup[1]=mail.get()
Label(root, text=' '*18, font=("bold", 10), fg='red').place(x=560,
y=180)
if age.get()=='':
Label(root, text='Enter Age!!', font=("bold", 10),
fg='red').place(x=560, y=270)
else:
Signup[2]=age.get()
Label(root, text=' '*18, font=("bold", 10), fg='red').place(x=560,
y=270)
name=StringVar()
Name = Entry(root,textvariable=name)
Name.place(x=430,y=130)
mail=StringVar()
Mail = Entry(root,textvariable=mail)
Mail.place(x=430,y=180)
Gender = IntVar()
Radiobutton(root, text="Male",padx = 5, variable=Gender,
value=1).place(x=425,y=230)
Radiobutton(root, text="Female",padx = 20, variable=Gender,
value=2).place(x=480,y=230)
age=StringVar()
Age = Entry(root,textvariable=age)
Age.place(x=430,y=280)
# Refresh
refresh=Button(root, text='⟲', font=("bold", 10), bg='light blue', padx=10,
pady=5, command=signup)
refresh.place(x=847,y=0)
#__________________________________________________________________________________
__________________________________
#__________________________________________________________________________________
__________________________________
def login():
global root
for widget in root.winfo_children():
widget.destroy()
def confirm():
global logged
try:
db=c.connect(host='localhost', user='root', passwd='123456',
database='rail')
cur=db.cursor()
cur.execute("select * from email where mail='{}'".format(mail.get()))
x=cur.fetchone()
for i in range(4):
Signup[i]=x[i]
db.commit()
except:
logged=False
raise
if Signup[1]==mail.get():
logged=True
Main()
label_0 = Label(root, text="Login",width=20,font=("bold", 20))
label_0.place(x=180,y=53)
mail=StringVar()
Mail = Entry(root,textvariable=mail, width=24, borderwidth=5, font=("bold",
10))
Mail.place(x=330,y=180)
if __name__=='__main__':
Main()