Advertisement
ALENTL

main.py

Oct 31st, 2022
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. def stud_lgn_btn(window):
  2.     # Killing the previous window and moving to the student window
  3.     window.destroy()
  4.  
  5.     # Making the tkinter window global
  6.     global root
  7.  
  8.     # Creating new window
  9.     root = Tk()
  10.  
  11.     root.title("STUDENT LOGIN")
  12.     root.geometry("960x600")
  13.     root.resizable(0, 0)
  14.     root.iconbitmap("./ico/student.ico")
  15.  
  16.     # Creating String Vars
  17.     global username_var
  18.     global passw_var
  19.     username_var = StringVar()
  20.     passw_var = StringVar()
  21.  
  22.     # Creating the background image variable
  23.     bg = PhotoImage(file="./img/all_lgn.png")
  24.  
  25.     # Creating the label background
  26.     l1 = Label(root, image=bg)
  27.     l1.place(x=0, y=0)
  28.  
  29.     # Creating student login text
  30.     l2 = Label(root, text="STUDENT LOGIN", background="#413E91",
  31.                font=("times new roman", 20, "bold"), fg="black")
  32.     l2.place(x=385, y=13)
  33.  
  34.     # Creating the login username text
  35.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  36.     lgnt1.place(x=40, y=140)
  37.  
  38.     # Creating the username login entry form
  39.     global user
  40.     user = Entry(root, textvariable=username_var, width=20)
  41.     user.place(x=140, y=140)
  42.  
  43.     # Creating the login password text
  44.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  45.     lgnt2.place(x=40, y=180)
  46.  
  47.     # Creating the password entry form
  48.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  49.     pswd.place(x=140, y=180)
  50.  
  51.     # Creating the submit button
  52.     submit = Button(root, text="SUBMIT", command=stud_lgn)
  53.     submit.place(x=130, y=220)
  54.  
  55.     root.mainloop()
  56.  
  57. """
  58. The stud_lgn() function is used to check for the username and password in the database and make further movements
  59. Tt uses the global username_var and password_var for checking the values
  60. It used .get() method to get the str() return of the entered value from the report
  61. Then that value is used to validate the student using mysql connection
  62.  
  63. If the entered value is correct then this window proceeds into stud_home()
  64. If not then the window will show an error message stating 'Cannot find such a user with the given username and passweord. Please retry'
  65. """
  66. def stud_lgn():
  67.     name = username_var.get()
  68.     passw = passw_var.get()
  69.  
  70.     cur.execute(
  71.         "SELECT * FROM STUDENTS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  72.  
  73.     a = cur.fetchone()
  74.  
  75.     global L
  76.     L = []
  77.  
  78.     if a !=None and len(a) != 0:
  79.         for k in a:
  80.             L.append(k)
  81.  
  82.         root.destroy()
  83.         stud_home()
  84.        
  85.     else:
  86.         messagebox.showerror(
  87.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  88.  
  89.     username_var.set("")
  90.     passw_var.set("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement