Advertisement
imroz229

Untitled

Apr 23rd, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.64 KB | Source Code | 0 0
  1.  
  2. import tkinter as tk
  3. #import PIL
  4. #from PIL import Image, ImageTk
  5. from tkinter import messagebox
  6. # import mysql.connector as my
  7. import sys
  8. import calendar
  9.  
  10.  
  11. w1=tk.Tk()
  12. w1.geometry('1366x720')
  13. w1.title("Login Page")
  14.  
  15. # Variables to store entered values on login page
  16. uservalue=tk.StringVar()
  17. passwordvalue=tk.StringVar()
  18.  
  19.  
  20.  
  21.  
  22. # Function to be called if Login btn is clicked
  23.  
  24. counter=0
  25.  
  26. def login():
  27.    
  28.     # connection
  29.     import mysql.connector as con
  30.     connection = con.connect(host="localhost", user="root", password="imroz", database="railway")
  31.  
  32.     cursor = connection.cursor()
  33.  
  34.  
  35.     if uservalue.get() == "" or passwordvalue.get() == "":
  36.         messagebox.showerror("Error", "All fields are required", parent=w1)
  37.         sys.exit()
  38.  
  39.  
  40.  
  41.  
  42.     #         calculating number of rows in the database
  43.     cursor.execute("select count(*) from users")
  44.     afetch=cursor.fetchone()
  45.     bfetch=afetch[0]  #It has the number of rows
  46.  
  47.     username = uservalue.get()
  48.     password = passwordvalue.get()
  49.  
  50. #     Checking if username and password are correct and match
  51.     cursor.execute('select username,password from users where username=username and password=password')
  52.     row=cursor.fetchall()
  53.  
  54.     global counter
  55.  
  56.     # as declared currently counter=0
  57.  
  58.     for i in range(0,bfetch):
  59.         if(row[i][0]==username and row[i][1]==password):
  60.             counter=1
  61.     if(counter==1):
  62.         messagebox.showinfo("Found","logging in")
  63.         messagebox.showinfo("Hello", "Please close this window to continue")
  64.         # print("found")
  65.        
  66.  
  67.     else:
  68.         messagebox.showinfo("Not found","password and uservalue  does not match")
  69.  
  70.     connection.close()
  71.  
  72. # Variables for storing entered sign up users
  73. user2value=tk.StringVar()
  74. pass2value=tk.StringVar()
  75. emailvalue=tk.StringVar()
  76. confpassvalue=tk.StringVar()
  77.     # function  to be called if Register button clicked
  78.  
  79. # If Register btn is clicked
  80.  
  81. def register():
  82.     if (user2value.get()==""or emailvalue.get()==""or pass2value.get()==""or confpassvalue.get()==""):
  83.          # phonevalue is left
  84.         messagebox.showerror("Error","All Fields Are Required",parent=w1)
  85.  
  86.     elif pass2value.get()!=confpassvalue.get():
  87.         messagebox.showerror("Error","Password and Confirm Password Should Be Same",parent=w1)
  88.     else:
  89.         printuser=user2value.get()
  90.         printemail=emailvalue.get()
  91.         printpass=pass2value.get()
  92.         # printphone=phonevalue.get()
  93.  
  94.  
  95.     # connection
  96.     import mysql.connector as con
  97.     connection = con.connect(host="localhost", user="root", password="imroz", database="railway")
  98.  
  99.     cursor = connection.cursor()
  100.  
  101.  
  102.     '''cursor.execute("INSERT INTO users VALUES(%s,%s,%s)",(printuser,printpass,printemail))
  103.    messagebox.showinfo("Success","Signed Up")
  104.    print(printuser,printpass,printemail)'''
  105.  
  106. #     trial
  107.     cursor.execute("INSERT INTO users (username,password,email) VALUES (%s, %s , %s)", (printuser, printpass, printemail))
  108.     connection.commit()
  109.  
  110.  
  111.     # connnection.commit()
  112.  
  113.     connection.close()
  114.  
  115.     messagebox.showinfo("Success", "Register Succesful"
  116.  
  117.                         , parent=w1)
  118.     messagebox.showinfo("Hello","Please Login to continue" )
  119.  
  120.        
  121.  
  122.  
  123. def Register():
  124.     f = tk.PhotoImage(file='back.png')
  125.     background_label = tk.Label(w1, image=f)
  126.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  127.     frame_input2 = tk.Frame(w1, bg='#6b4f83')
  128.  
  129.     frame_input2.place(x=320, y=130, height=500, width=630)
  130.  
  131.     label1 = tk.Label(frame_input2, text="Register Here", font=('impact', 28, 'bold'),
  132.  
  133.                    fg="blue", bg='white',borderwidth=5, relief=tk.RIDGE)
  134.  
  135.     label1.place(x=45, y=20)
  136.  
  137.  
  138.  
  139.     # username
  140.     user2 = tk.Label(frame_input2, text="Username", font=("Goudy old style", 20, "bold"),
  141.  
  142.                    fg='orangered', bg='white')
  143.  
  144.     user2.place(x=30, y=95)
  145.  
  146.     uentry2= tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  147.  
  148.                        bg='lightgray' ,textvariable=user2value,borderwidth=3, relief=tk.SUNKEN)
  149.  
  150.     uentry2.place(x=30, y=145, width=270, height=35)
  151.     a1=uservalue.get()
  152.     # Password
  153.     pass2 = tk.Label(frame_input2, text="Password", font=("Goudy old style", 20, "bold"),
  154.  
  155.                    fg='orangered', bg='white')
  156.  
  157.     pass2.place(x=30, y=195)
  158.  
  159.     passentry2 = tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  160.  
  161.                         bg='lightgray',textvariable=pass2value,borderwidth=3, relief=tk.SUNKEN)
  162.  
  163.     passentry2.place(x=30, y=245, width=270, height=35)
  164.     b1=pass2value.get()
  165.     # email
  166.     email= tk.Label(frame_input2, text="Email-id", font=("Goudy old style", 20, "bold"),
  167.  
  168.                    fg='orangered', bg='white')
  169.  
  170.     email.place(x=330, y=95)
  171.  
  172.     emailentry = tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  173.  
  174.                         bg='lightgray',textvariable=emailvalue,borderwidth=3, relief=tk.SUNKEN)
  175.  
  176.  
  177.     emailentry.place(x=330, y=145, width=270, height=35)
  178.     c1=emailvalue.get()
  179.     # confirm password
  180.     confpass= tk.Label(frame_input2, text="Confirm Password",
  181.  
  182.                    font=("Goudy old style", 20, "bold"), fg='orangered', bg='white')
  183.  
  184.     confpass.place(x=330, y=195)
  185.  
  186.     confpassentry = tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  187.  
  188.                         bg='lightgray',textvariable=confpassvalue,borderwidth=3, relief=tk.SUNKEN)
  189.     d1=confpassvalue.get()
  190.     confpassentry.place(x=330, y=245, width=270, height=35)
  191.    
  192.     # sign up btn
  193.     sig = tk.Button(frame_input2, command=register, text="Register"
  194.  
  195.                     , cursor="hand2", font=("times new roman", 15), fg="white",
  196.  
  197.                     bg="orangered", bd=0, width=15, height=1,borderwidth=3, relief=tk.RIDGE)
  198.  
  199.     sig.place(x=50, y=340)
  200.    
  201.     # If already Registered
  202.  
  203.     rego=tk.Button(frame_input2,command=main, text="Already Registered? Login"
  204.  
  205.                     , cursor="hand2", font=("times new roman", 15), fg="white",
  206.  
  207.                     bg="orangered", bd=0, width=30, height=1,borderwidth=3, relief=tk.RIDGE)
  208.     rego.place(x=270,y=340)
  209.     w1.mainloop()
  210.  
  211.    
  212.    
  213.    
  214.  
  215. def main(): #This method is responsible for the main login page
  216.  
  217. # Photo goes here
  218.  
  219.     f=tk.PhotoImage(file='back.png')
  220.     background_label=tk.Label(w1,image=f)
  221.     background_label.place(x=0,y=0,relwidth=1,relheight=1)
  222.  
  223. # Photo Ends here
  224.  
  225. # Creating frame
  226.  
  227.     frame_input=tk.Frame(w1,bg='#6b4f83')
  228.     frame_input.place(x=320,y=130,height=500,width=400)
  229.  
  230. #LABELLING AND PACKING
  231.  
  232.     x=tk.Label(w1,text="IRCTC LOGIN", font=("SF PRO DISPLAY", 30) , fg='Blue',borderwidth=4, relief=tk.RIDGE)
  233.  
  234.     user=tk.Label(w1,text="Username",font=("Century Gothic",25,"bold"),  fg='orangered',borderwidth=3, relief=tk.SUNKEN)
  235.  
  236.  
  237.     password=tk.Label(w1,text="Password", font=("Century Gothic",25,'bold'),fg='orangered',borderwidth=3, relief=tk.SUNKEN)
  238.     x.place(x=400,y=150)
  239.     user.place(x=340,y=230)
  240.     password.place(x=340,y=340)
  241.  
  242. # using login variables as global
  243.     global uservalue
  244.     global passwordvalue
  245.  
  246.     userentry=tk.Entry(w1,font=("times new roman",22,"bold"),fg='blue',bg='lightgray',textvariable=uservalue,borderwidth=2,relief=tk.SUNKEN)
  247.     userentry.place(x=340,y=280)
  248.  
  249.     passwordentry=tk.Entry(w1,font=("times new roman",22,"bold"),fg='blue',bg='lightgray',textvariable=passwordvalue,borderwidth=2,relief=tk.SUNKEN)
  250.     passwordentry.place(x=340,y=390)
  251.  
  252.  
  253.     # login button
  254.     btn1=tk.Button(frame_input,text="Login",command=login,
  255.  
  256.                   font=("times new roman",15),fg="white",bg="orangered",
  257.  
  258.                   bd=0,width=15,height=1,borderwidth=3, relief=tk.RIDGE)
  259.  
  260.     btn1.place(x=90,y=340)
  261.  
  262. # signup button
  263.  
  264.     btn2=tk.Button(frame_input,command=Register,text="Not Registered? Register",
  265.  
  266.                 font=("calibri",15),bg='orange',fg="white",bd=0,borderwidth=3, relief=tk.RIDGE)
  267.  
  268.     btn2.place(x=70,y=390)
  269.  
  270.  
  271.     w1.mainloop()
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. main()
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287. # Project2
  288.  
  289.  
  290. # import project1 as k
  291. import tkinter as tk
  292. import PIL
  293. from PIL import Image,ImageTk
  294. import random
  295. from tkinter import messagebox
  296. from tkcalendar import Calendar, DateEntry
  297. import sys
  298. # Variables to store which class is selected
  299. gen,sleep,a1,a2=0,0,0,0
  300. # if booking successful
  301. def final():
  302.     global number_of_passengers
  303.     # print(number_of_passengers)
  304.     global name1
  305.     global age1
  306.     global pnrvalue1
  307.     global name2
  308.     global pnrvalue2
  309.     print(name1.get())
  310.     global gen
  311.     global sleep
  312.     global a1
  313.     global a2
  314.        
  315.     tk.Frame(w2,bg="#49577b").place(x=0, y=0, height=720, width=1366)
  316.     tk.Label(text="BOOKING SUCCESSFUL",fg="GREEN",font=("algerian 30"),borderwidth=3, relief=tk.SUNKEN).place(x=500,y=100)
  317.  
  318.    
  319.  
  320.     if number_of_passengers==1:
  321.         tk.Label(text="Passenger :",font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  322.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=300)
  323.  
  324.         tk.Label(text=name1.get(),font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  325.         borderwidth=3, relief=tk.SUNKEN).place(x=400,y=300)
  326.  
  327.         tk.Label(text="pnr :",font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  328.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=450)
  329.  
  330.         tk.Label(text=pnrvalue1,font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  331.         borderwidth=3, relief=tk.SUNKEN).place(x=400,y=450)
  332.         if(gen==1):
  333.             tk.Label(text="YOUR BOOKING IS IN GENERAL",
  334.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=600)
  335.         elif(sleep==1):
  336.             tk.Label(text="YOUR BOOKING IS IN SLEEPER ",
  337.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=600)
  338.         elif(a1==1):
  339.             tk.Label(text="YOUR BOOKING IS IN AC 3rd TIER ",
  340.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=600)
  341.         elif(a2==1):
  342.             tk.Label(text="YOUR BOOKING IS IN AC 2nd TIER",
  343.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=600)
  344.        
  345.  
  346.     elif(number_of_passengers==2):
  347.         tk.Label(text="Passenger 1 :",font=("CENTURY GOTHIC",20,"bold"), fg="orangered",
  348.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=200)
  349.  
  350.         tk.Label(text=name1.get(),font=("CENTURY GOTHIC",20,"bold"),fg="orangered"
  351.         ,borderwidth=3, relief=tk.SUNKEN).place(x=400,y=200)
  352.  
  353.         tk.Label(text="pnr 1:",font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  354.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=250)
  355.  
  356.         tk.Label(text=pnrvalue1,font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  357.         borderwidth=3, relief=tk.SUNKEN).place(x=400,y=250)
  358.  
  359.         tk.Label(text="Passenger 2:",font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  360.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=400)
  361.  
  362.         tk.Label(text=name2.get(),font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  363.         borderwidth=3, relief=tk.SUNKEN).place(x=400,y=400)
  364.  
  365.         tk.Label(text="pnr 2:",font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  366.         borderwidth=3, relief=tk.SUNKEN).place(x=100,y=500)
  367.  
  368.         tk.Label(text=pnrvalue1,font=("CENTURY GOTHIC",20,"bold"),fg="orangered",
  369.         borderwidth=3, relief=tk.SUNKEN).place(x=400,y=500)
  370.  
  371.         if(gen==1):
  372.             tk.Label(text="YOUR BOOKING IS IN GENERAL",
  373.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=560)
  374.         elif(sleep==1):
  375.             tk.Label(text="YOUR BOOKING IS IN SLEEPER ",
  376.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=560)
  377.         elif(a1==1):
  378.             tk.Label(text="YOUR BOOKING IS IN AC 3rd TIER ",
  379.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=560)
  380.         elif(a2==1):
  381.             tk.Label(text="YOUR BOOKING IS IN AC 2nd TIER",
  382.             font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=560)
  383.     tk.Label(text="Your Booking is on:",font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=200,y=650)
  384.     tk.Label(text=str1,font=("CENTURY GOTHIC",20,"bold"),fg="orangered").place(x=450,y=650)
  385.  
  386.  
  387. pnr=0
  388. pnrvalue1,pnrvalue2='',''
  389. number_of_passengers=0
  390. # if book btn clicked
  391. def booked():
  392.  
  393.      # if entry boxes are empty show error
  394.    
  395.     '''if(name1.get()=='' or age1.get()=='' or aadhar1.get()==''):
  396.        messagebox.showerror("Error","All fields are Required")
  397.        sys.exit()
  398.  
  399.    elif(name1.get()=='' or age1.get()=='' or aadhar1.get()=='' or name2.get()=='' or age2.get()=='' or aadhar2.get()==''):
  400.        messagebox.showerror("Error","All fields are Required")
  401.        sys.exit()'''
  402.  
  403.    
  404.     global number_of_passengers
  405.     m=aadhar1.get()
  406.     n=aadhar2.get()
  407.     if m!='' and n!='':
  408.         number_of_passengers=2
  409.     elif m=='' and n!='':
  410.         number_of_passengers=1
  411.     elif m!='' and n=='':
  412.         number_of_passengers=1
  413.     else:
  414.         number_of_passengers=0
  415.  
  416.     print(number_of_passengers)
  417.  
  418.  
  419.  
  420.     global pnr
  421.     global pnrvalue1
  422.     global pnrvalue2
  423.    
  424.     '''if number_of_passengers==3:
  425.        pnr=3'''
  426.     if number_of_passengers==2:
  427.         pnr=2
  428.     elif number_of_passengers==1:
  429.         pnr=1
  430.     else:
  431.         pnr=0
  432.     '''if(pnr==3):
  433.        
  434.        pnrvalue1="D"+str(random.randint(1,9))+str(random.randint(0,9))+str(random.randint(1,9))+str(random.randint(1,9))+str(random.randint(1,9))
  435.        
  436.        pnrvalue2='H'+str(random.randint(1,9))+str(random.randint(1,9))+"R"+str(random.randint(1,9))+str(random.randint(1,9))
  437.        pnrvalue3=str(random.randint(1,9))+"G"+str(random.randint(1,9))+str(random.randint(1,9))+str(random.randint(1,9))+str(random.randint(1,9))'''
  438.     if(pnr==2):
  439.         pnrvalue1="D"+str(random.randint(1,9))+str(random.randint(0,9))+str(random.randint(1,9))+str(random.randint(1,9))+str(random.randint(1,9))
  440.        
  441.         pnrvalue2='H'+str(random.randint(1,9))+str(random.randint(1,9))+"R"+str(random.randint(1,9))+str(random.randint(1,9))
  442.     elif(pnr==1):
  443.         pnrvalue1="D"+str(random.randint(1,9))+str(random.randint(0,9))+str(random.randint(1,9))+str(random.randint(1,9))+str(random.randint(1,9))
  444.        
  445.     print(pnrvalue1)
  446.     print(pnrvalue2)
  447.    
  448.     n1=name1.get()
  449.     n2=name2.get()
  450.     a1=age1.get()
  451.     a2=age2.get()
  452.     if number_of_passengers==2:
  453.         import mysql.connector as my
  454.         con=my.connect(host="localhost",user='root',password='imroz',db='railway')
  455.         cursor=con.cursor()
  456.        
  457.         cursor.execute("INSERT INTO passenger values(%s,%s,%s,%s)",(n1,m,a1,pnrvalue1))
  458.         cursor.execute("INSERT INTO passenger values(%s,%s,%s,%s)",(n2,n,a2,pnrvalue2))
  459.         con.commit()
  460.  
  461.         final()
  462.         # print('here')
  463.     elif number_of_passengers==1:
  464.         import mysql.connector as my
  465.         con=my.connect(host="localhost",user='root',password='imroz',db='railway')
  466.         cursor=con.cursor()
  467.        
  468.         cursor.execute("INSERT INTO passenger values(%s,%s,%s,%s)",(n1,m,a1,pnrvalue1))
  469.        
  470.         con.commit()
  471.  
  472.         final()
  473. # If user wants to add more details
  474. def detail2():
  475.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  476.     frame_input2 = tk.Frame(w2, bg='#4a7491')
  477.  
  478.     frame_input2.place(x=30, y=15, height=690, width=1300)
  479.  
  480.     label1 = tk.Label(frame_input2, text="ENTER THE DETAILS", font=('impact', 32, 'bold'),
  481.  
  482.                    fg="blue", bg='white',borderwidth=3, relief=tk.SUNKEN)
  483.  
  484.     label1.place(x=400, y=90)
  485.  
  486.  
  487.     global name1
  488.     global aadhar1
  489.     global age1
  490.     global name2
  491.     global age2
  492.     global aadhar2
  493.  
  494. #    first name
  495.     tk.Label(frame_input2, text="NAME", font=("Goudy old style", 20, "bold"),
  496.  
  497.                    fg='orangered', bg='lightgray',borderwidth=3, relief=tk.SUNKEN).place(x=50,y=250)
  498.  
  499.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  500.  
  501.                        bg='lightgray' ,textvariable=name1,borderwidth=3, relief=tk.SUNKEN).place(x=250,y=250)
  502.  
  503.     # second name
  504.  
  505.     tk.Label(frame_input2, text="NAME", font=("Goudy old style", 20, "bold"),
  506.  
  507.                    fg='orangered', bg='LIGHTGRAY',borderwidth=3, relief=tk.SUNKEN).place(x=700,y=250)
  508.  
  509.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  510.  
  511.                        bg='lightgray' ,textvariable=name2,borderwidth=3, relief=tk.SUNKEN).place(x=1000,y=250)
  512.    
  513.     # first age
  514.     tk.Label(frame_input2, text="AGE", font=("Goudy old style", 20, "bold"),
  515.  
  516.                    fg='orangered', bg='lightgray',borderwidth=3, relief=tk.SUNKEN).place(x=50,y=350)
  517.  
  518.    
  519.  
  520.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  521.  
  522.                         bg='lightgray',textvariable=age1,borderwidth=3, relief=tk.SUNKEN).place(x=250,y=350)
  523.  
  524.     # second age
  525.  
  526.     tk.Label(frame_input2, text="AGE", font=("Goudy old style", 20, "bold"),
  527.  
  528.                    fg='orangered', bg='lightgray',borderwidth=3, relief=tk.SUNKEN).place(x=700,y=350)
  529.  
  530.    
  531.  
  532.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  533.  
  534.                         bg='lightgray',textvariable=age2,borderwidth=3, relief=tk.SUNKEN).place(x=1000,y=350)
  535.  
  536.  
  537.     # aadhar1
  538.     tk.Label(frame_input2, text="AADHAR NO.", font=("Goudy old style", 20, "bold"),
  539.  
  540.                    fg='orangered', bg='lightgray',borderwidth=3, relief=tk.SUNKEN).place(x=50,y=450)
  541.  
  542.    
  543.  
  544.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  545.  
  546.                         bg='lightgray',textvariable=aadhar1,borderwidth=3, relief=tk.SUNKEN).place(x=250,y=450)
  547.    
  548.  
  549.     # aadhar2
  550.     tk.Label(frame_input2, text="AADHAR NO.", font=("Goudy old style", 20, "bold"),
  551.  
  552.                    fg='orangered', bg='lightgray',borderwidth=3, relief=tk.SUNKEN).place(x=700,y=450)
  553.  
  554.    
  555.  
  556.     tk.Entry(frame_input2, font=("times new roman", 15, "bold"),
  557.  
  558.                         bg='lightgray',textvariable=aadhar2,borderwidth=3, relief=tk.SUNKEN).place(x=1000,y=450)
  559.    
  560.    
  561.     # sign up btn
  562.     sig = tk.Button(frame_input2, command=booked, text="BOOK"
  563.  
  564.                     , cursor="hand2", font=("times new roman", 19), fg="white",
  565.  
  566.                     bg="orangered", bd=0, width=15, height=1,borderwidth=3, relief=tk.RIDGE)
  567.  
  568.     sig.place(x=400, y=600)
  569.    
  570.    
  571.    
  572.     w2.mainloop()
  573.    
  574.  
  575. # If any coach is selected for passenger details to be entered
  576.  
  577. def detail1():
  578.     #LABELLING AND PACKING
  579.  
  580.     tk.Label(w2,text="PASSENGER DETAILS", font=("SF PRO DISPLAY", 30) , fg='Blue',borderwidth=4, relief=tk.RIDGE).place(x=500,y=50)
  581.  
  582.     tk.Label(w2,text="NAME",font=("Century Gothic",25,"bold"),  fg='orangered',borderwidth=3, relief=tk.SUNKEN).place(x=200,y=200)
  583.  
  584.  
  585.     tk.Label(w2,text="AGE", font=("Century Gothic",25,'bold'),fg='orangered',borderwidth=3, relief=tk.SUNKEN).place(x=200,y=300)
  586.  
  587.     tk.Label(w2,text="AADHAR NUMBER", font=("Century Gothic",25,'bold'),fg='orangered',borderwidth=3, relief=tk.SUNKEN).place(x=135,y=400)
  588.  
  589.  
  590. # using login variables as global
  591.     global name1
  592.     global age1
  593.     global aadhar1
  594.  
  595.     tk.Entry(w2,font=("times new roman",22,"bold"),fg='blue',bg='lightgray',textvariable=name1,borderwidth=2,relief=tk.SUNKEN).place(x=450,y=200)
  596.    
  597.     tk.Entry(w2,font=("times new roman",22,"bold"),fg='blue',bg='lightgray',textvariable=age1,borderwidth=2,relief=tk.SUNKEN).place(x=450,y=300)
  598.    
  599.  
  600.     tk.Entry(w2,font=("times new roman",22,"bold"),fg='blue',bg='lightgray',textvariable=aadhar1,borderwidth=2,relief=tk.SUNKEN).place(x=450,y=400)
  601.  
  602.     checkbtn=tk.IntVar()
  603.  
  604.     tk.Checkbutton(w2, text = "DO YOU AGREE TO THE T&C ?",
  605.                       variable = checkbtn,
  606.                       onvalue = 1,
  607.                       offvalue = 0,
  608.                       height = 2,bg="light blue",fg='orangered'
  609.                       ).place(x=350,y=610)
  610.     # login button
  611.     btn1=tk.Button(text="BOOK YOUR TICKET",command=booked,
  612.  
  613.                   font=("times new roman",15),fg="white",bg="orangered",
  614.  
  615.                   bd=0,width=22,height=1,borderwidth=3, relief=tk.RIDGE)
  616.  
  617.     btn1.place(x=250,y=550)
  618.  
  619. # signup button
  620.  
  621.     btn2=tk.Button(command=detail2,text="MORE PASSANGERS?",
  622.  
  623.                 font=("calibri",15),bg='orange',fg="white",bd=0,borderwidth=3, relief=tk.RIDGE)
  624.  
  625.     btn2.place(x=560,y=550)
  626.  
  627.            
  628.        
  629.  
  630.  
  631.     # print(checkbtn.get())
  632.    
  633.     w2.mainloop()
  634.  
  635.  
  636.  
  637.  
  638. # functions if different coaches are selected
  639. def general():
  640.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  641.     frame_input2 = tk.Frame(w2, bg='#4a7491')
  642.  
  643.     frame_input2.place(x=30, y=15, height=690, width=1300)
  644.     global gen
  645.     gen=1
  646.     detail1()
  647.  
  648.    
  649.  
  650.  
  651. def sleeper():
  652.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  653.     frame_input2 = tk.Frame(w2, bg='#4a7491')
  654.  
  655.     frame_input2.place(x=30, y=15, height=690, width=1300)
  656.     global sleep
  657.     sleep=1
  658.     detail1()
  659.  
  660. def ac1():
  661.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  662.     frame_input2 = tk.Frame(w2, bg='#4a7491')
  663.  
  664.     frame_input2.place(x=30, y=15, height=690, width=1300)
  665.     global a1
  666.     a1=1
  667.     #for ac3rd
  668.     detail1()
  669.  
  670. def ac2():
  671.     background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  672.     frame_input2 = tk.Frame(w2, bg='#4a7491')
  673.  
  674.     frame_input2.place(x=30, y=15, height=690, width=1300)
  675.     global a2
  676.     a2=1
  677.     #for ac2nd
  678.     detail1()
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686. # variables storing train names and distance
  687. t1,t2,t3,distance='','','',''
  688. def train():
  689.     source=fromvalue.get()
  690.     destination=tovalue.get()
  691.     source=source.upper()
  692.     destination=destination.upper()
  693.     import mysql.connector as connection
  694.     con=connection.connect(host="localhost",user="root",password="imroz",db="railway")
  695.     cursor=con.cursor()
  696.     cursor.execute("select count(*) from detail")
  697.     afetch=cursor.fetchone()
  698.     bfetch=afetch[0]  #It has the number of rows
  699.  
  700.     c=0
  701.     global distance
  702.     global t1
  703.     global t2
  704.     global t3
  705.    
  706. #     Checking if source and destination  match the database
  707.     cursor.execute('select * from detail where source=source AND destination=destination')
  708.     row=cursor.fetchall()
  709.     # print(row[1])
  710. # global counter
  711.  
  712.     # as declared currently counter=0
  713.  
  714.     for i in range(0,bfetch):
  715.         if(row[i][0]==source and row[i][1]==destination):
  716.                 c=1
  717.                 distance=row[i][2]
  718.                 t1=row[i][3]
  719.                 t2=row[i][4]
  720.                 t3=row[i][5]
  721.  
  722.  
  723.     if(c==1):
  724.        
  725.         print(distance,t1,t2,t3)
  726.    
  727.  
  728.  
  729.     # DISPLAYING AVAILABLE TRAINS WITH COST
  730.  
  731.     if ( fromvalue.get() == "" or tovalue.get() == "" ):
  732.         messagebox.showerror("Error", "All Fields Are Required", parent=w2)
  733.  
  734.     else:
  735.         f = tk.PhotoImage(file='train.png')
  736.         background_label = tk.Label(w2, image=f)
  737.         background_label.place(x=1000, y=1500, relwidth=1, relheight=1)
  738.         frame_input2 = tk.Frame(w2, bg='#6e6394')
  739.  
  740.         frame_input2.place(x=183, y=75, height=590, width=960)
  741.  
  742.         tk.Label(text="Select Your Train And Class",font=("ALGERIAN",26),bg="#2a365c",fg="WHITE",borderwidth=3, relief=tk.SUNKEN).place(x=420,y=100)
  743.  
  744.         tk.Label(text="Available Trains",font=("Century Gothic",24),bg="#2a365c",fg="white",borderwidth=3, relief=tk.SUNKEN).place(x=210,y=180)
  745.         #train label 1
  746.  
  747.         tlabel1=tk.Label(text=t1,font=("Century Gothic",18),bg='#2a365c',fg="white",borderwidth=3, relief=tk.SUNKEN).place(x=230,y=260)
  748.         tlabel2=tk.Label(text=t2,font=("CENTURY GOTHIC",18),bg='#2a365c',fg="white",borderwidth=3, relief=tk.SUNKEN).place(x=530,y=260)
  749.         tlabel3=tk.Label(text=t3,font=("CENTURY GOTHIC",18),bg='#2a365c',fg="white",borderwidth=3, relief=tk.SUNKEN).place(x=850,y=260)
  750.  
  751.         d=int(distance)
  752.         # Labelling coaches and their costs
  753.  
  754.         t1ag="GENERAL : "+str(random.randint(10,1000))+"\nCOST: "+str(d*1.5)
  755.         t2ag="GENERAL : "+str(random.randint(10,1000))+"\nCOST: "+str(d*1.5)
  756.         t3ag="GENERAL : "+str(random.randint(10,1000))+"\nCOST: "+str(d*1.5)
  757.        
  758.         t1as="SLEEPER : "+str(random.randint(10,700))+"\nCOST: "+str(d*2)
  759.         t2as="SLEEPER : "+str(random.randint(10,700))+"\nCOST: "+str(d*2)
  760.         t3as="SLEEPER : "+str(random.randint(10,700))+"\nCOST: "+str(d*2)
  761.  
  762.         t1aa1="AC 3 : "+str(random.randint(10,200))+"\nCOST: "+str(d*3)
  763.         t2aa1="AC 3 : "+str(random.randint(10,200))+"\nCOST: "+str(d*3)
  764.         t3aa1="AC 3 : "+str(random.randint(10,200))+"\nCOST: "+str(d*3)
  765.  
  766.         t1aa2="AC 2 : "+str(random.randint(10,150))+"\nCOST: "+str(d*3.5)
  767.         t2aa2="AC 2 : "+str(random.randint(10,150))+"\nCOST: "+str(d*3.5)
  768.         t3aa2="AC 2 : "+str(random.randint(10,150))+"\nCOST: "+str(d*3.5)  
  769.  
  770.  
  771.        
  772.         b1t1=tk.Button(text=t1ag,font=("Century Gothic bold",10),
  773.         bg='#4a7491',fg="#eb3305",width=20,command=general,borderwidth=3, relief=tk.RIDGE).place(x=240,y=310)
  774.  
  775.         b2t1=tk.Button(text=t1as,font=("Century Gothic bold",10),bg='#4a7491',
  776.         fg="#eb3305",width=20,command=sleeper,borderwidth=3, relief=tk.RIDGE).place(x=240,y=360)
  777.  
  778.         b3t1=tk.Button(text=t1aa1,font=("Century Gothic bold",10),
  779.         bg='#4a7491',fg="#eb3305",width=20,command=ac1,borderwidth=3, relief=tk.RIDGE).place(x=240,y=410)
  780.  
  781.         b4t1=tk.Button(text=t1aa2,font=("Century Gothic bold",10)
  782.         ,bg='#4a7491',fg="#eb3305",width=20,command=ac2,borderwidth=3, relief=tk.RIDGE).place(x=240,y=460)
  783.  
  784.         b1t2=tk.Button(text=t2ag,font=("Century Gothic bold",10),
  785.         bg='#4a7491',fg="#eb3305",width=20,command=general,borderwidth=3, relief=tk.RIDGE).place(x=550,y=310)
  786.  
  787.         b2t2=tk.Button(text=t2as,font=("Century Gothic bold",10),
  788.         bg='#4a7491',fg="#eb3305",width=20,command=sleeper,borderwidth=3, relief=tk.RIDGE).place(x=550,y=360)
  789.  
  790.         b3t2=tk.Button(text=t2aa1,font=("Century Gothic bold",10),
  791.         bg='#4a7491',fg="#eb3305",width=20,command=ac1,borderwidth=3, relief=tk.RIDGE).place(x=550,y=410)
  792.  
  793.         b4t2=tk.Button(text=t2aa2,font=("Century Gothic bold",10),
  794.         bg='#4a7491',fg="#eb3305",width=20,command=ac2,borderwidth=3, relief=tk.RIDGE).place(x=550,y=460)
  795.  
  796.         b1t3=tk.Button(text=t3ag,font=("Century Gothic bold",10),
  797.         bg='#4a7491',fg="#eb3305",width=20,command=general,borderwidth=3, relief=tk.RIDGE).place(x=910,y=310)
  798.  
  799.         b2t3=tk.Button(text=t3as,font=("Century Gothic bold",10),
  800.         bg='#4a7491',fg="#eb3305",width=20,command=sleeper,borderwidth=3, relief=tk.RIDGE).place(x=910,y=360)
  801.  
  802.         b3t3=tk.Button(text=t3aa1,font=("Century Gothic bold",10),
  803.         bg='#4a7491',fg="#eb3305",width=20,command=ac1,borderwidth=3, relief=tk.RIDGE).place(x=910,y=410)
  804.  
  805.         b4t3=tk.Button(text=t3aa2,font=("Century Gothic bold",10),
  806.         bg='#4a7491',fg="#eb3305",width=20,command=ac2,borderwidth=3, relief=tk.RIDGE).place(x=910,y=460)
  807.  
  808.  
  809.  
  810.  
  811. if(counter==1):
  812.     w2=tk.Tk()
  813.     w2.geometry('1366x720')
  814.     w2.title("Select train and date")
  815.     f=tk.PhotoImage(file='train.png')
  816.     background_label=tk.Label(w2,image=f)
  817.     background_label.place(x=0,y=0,relwidth=1,relheight=1)
  818.  
  819.     name1=tk.StringVar()
  820.     age1=tk.StringVar()
  821.     aadhar1=tk.StringVar()
  822.     name2=tk.StringVar()
  823.     age2=tk.StringVar()
  824.     aadhar2=tk.StringVar()
  825.  
  826.        
  827.  
  828.  
  829.  
  830.  
  831.  
  832.     frame=tk.Frame(w2,bg='#6e6394')
  833.     frame.place(x=220,y=130,height=500,width=880)
  834.  
  835.     datevalue=tk.StringVar()
  836.     fromvalue=tk.StringVar()
  837.     tovalue=tk.StringVar()
  838.  
  839.     datelabel=tk.Label(w2,text="Enter Date of Travel",font=("Goudy old style", 20, "bold"),bg="lightgray", fg='orangered',borderwidth=3, relief=tk.SUNKEN).place(x=350,y=170)
  840.     fromlabel=tk.Label(w2,text="FROM",font=("Goudy old style", 20, "bold"), fg='orangered',bg="lightgray", relief=tk.SUNKEN).place(x=350,y=320)
  841.     tolabel=tk.Label(w2,text="TO",font=("Goudy old style", 20, "bold"), fg='orangered',bg="lightgray",borderwidth=3, relief=tk.SUNKEN).place(x=350,y=420)
  842.  
  843.     # dateentry=tk.Entry(w2,font=("century gothic",20),textvariable=datevalue).place(x=700,y=170)
  844.     fromentry=tk.Entry(w2,font=("century gothic",20),bg="lightgray",textvariable=fromvalue,borderwidth=3, relief=tk.SUNKEN).place(x=700,y=320)
  845.     toentry=tk.Entry(w2,font=("century gothic",20),bg="lightgray",textvariable=tovalue,borderwidth=3, relief=tk.SUNKEN).place(x=700,y=420)
  846.  
  847.     btn=tk.Button(text="Search Trains",command=train,font=("GOUDY OLD STYLE",14,"bold"),borderwidth=3,fg='white',bg='orangered', relief=tk.SUNKEN).place(x=500,y=520)
  848.    
  849.     def getdate():
  850.         # print(cal.get_date())
  851.         y=cal.get_date()
  852.         global str1
  853.         str1=y.strftime("%d-%B-%y")
  854.  
  855.         print(str1)
  856.  
  857.     cal = DateEntry(w2, width= 10,font=("century gothic",20), background= "magenta3",
  858.      foreground= "white",bd=5,borderwidth=3, relief=tk.SUNKEN)
  859.  
  860.     cal.place(x=700,y=170)
  861.    
  862.  
  863.     btnc=tk.Button(w2,text="OK",font=("ALGERIAN",15),command=getdate,background="#3cc0c3",borderwidth=3, relief=tk.SUNKEN)
  864.     btnc.place(x=760,y=220)
  865.     w2.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement