Advertisement
ALENTL

main.py

Oct 31st, 2022
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.08 KB | None | 0 0
  1. # Including tkinter header to create and manage ui's
  2. from tkinter import messagebox
  3. from tkinter import *
  4.  
  5. # Using mysql-connector-python for mysql python connection
  6. import mysql.connector as mc
  7.  
  8. # Using customtkinter module for modern tkinter button
  9. import customtkinter
  10.  
  11. # Using Pillow module for the support of jpg images and resizing the images into specified
  12. from PIL import Image, ImageTk
  13.  
  14. # Using tkcalendar module to get date from leave entry into yyyy-mm-dd format
  15. from tkcalendar import DateEntry
  16.  
  17. # Using matplotlib to plot the graph into tkinter
  18. import matplotlib.pyplot as plt
  19. from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
  20. from matplotlib.backend_bases import key_press_handler
  21. from matplotlib.figure import Figure
  22.  
  23. # Using numpy module for faster array support
  24. import numpy as np
  25.  
  26. # Using time module to set program delay
  27. import time
  28.  
  29. # MySQL Objects and connection string
  30. cnx = mc.connect(host="localhost", user="alen",
  31.                  password="alen", database="school")
  32. #Setting buffered to True to get rid of unread results found error
  33. cur = cnx.cursor(buffered=True)
  34. cnx.autocommit = True
  35.  
  36. """
  37. Home function is the default home page. It consists of the  login page. It asks the user which group he/she belongs to ie (student, teacher, staff, admin)
  38. """
  39. def home():
  40.     window = Tk()
  41.     window.title("SCHOOL MANAGEMENT SYSTEM")
  42.     window.geometry("960x606")
  43.     window.resizable(0, 0)
  44.     window.iconbitmap("./ico/school.ico")
  45.  
  46.     # Creating background image variable
  47.     bg = PhotoImage(file="./img/login.png")
  48.  
  49.     # Creating the background label
  50.     l1 = Label(window, image=bg)
  51.     l1.place(x=0, y=0)
  52.  
  53.     # Creating the login text
  54.     l2 = Label(window, text="LOGIN", font=(
  55.         "times new roman", 20, "bold"), bg="#184800", fg="#ff007f")
  56.     l2.place(x=441, y=23)
  57.  
  58.     # Creating the student button
  59.     l3 = Button(window, text="STUDENT", width=15, font=(
  60.         "times new roman", 10, "bold"), command=lambda: stud_lgn_btn(window))
  61.     l3.place(x=435, y=100)
  62.  
  63.     # Creating the teacher button
  64.     l4 = Button(window, text="TEACHER", width=15, font=(
  65.         "times new roman", 10, "bold"), command=lambda: teacher_lgn_btn(window))
  66.     l4.place(x=435, y=140)
  67.  
  68.     # Creating the staff button
  69.     l5 = Button(window, text="STAFF", width=15, font=(
  70.         "times new roman", 10, "bold"), command=lambda: staff_lgn_btn(window))
  71.     l5.place(x=435, y=180)
  72.  
  73.     # Creating the admin button
  74.     l6 = Button(window, text="ADMIN", width=15, font=(
  75.         "times new roman", 10, "bold"), command=lambda: admin_lgn_btn(window))
  76.     l6.place(x=435, y=220)
  77.  
  78.     window.mainloop()
  79.  
  80. """
  81. The stud_lgn_btn() is a function that changes the window from home window to student login widnow.
  82. It accepts the parent window as it's param and destroys the window
  83. This page consists of username and password entry and a submit button
  84. The username and password are passed on to the username_var and password_var text variables respectively
  85. Then the submit button calls on the command stud_lgn()
  86. """
  87. def stud_lgn_btn(window):
  88.     # Killing the previous window and moving to the student window
  89.     window.destroy()
  90.  
  91.     # Making the tkinter window global
  92.     global root
  93.  
  94.     # Creating new window
  95.     root = Tk()
  96.  
  97.     root.title("STUDENT LOGIN")
  98.     root.geometry("960x600")
  99.     root.resizable(0, 0)
  100.     root.iconbitmap("./ico/student.ico")
  101.  
  102.     # Creating String Vars
  103.     global username_var
  104.     global passw_var
  105.     username_var = StringVar()
  106.     passw_var = StringVar()
  107.  
  108.     # Creating the background image variable
  109.     bg = PhotoImage(file="./img/all_lgn.png")
  110.  
  111.     # Creating the label background
  112.     l1 = Label(root, image=bg)
  113.     l1.place(x=0, y=0)
  114.  
  115.     # Creating student login text
  116.     l2 = Label(root, text="STUDENT LOGIN", background="#413E91",
  117.                font=("times new roman", 20, "bold"), fg="black")
  118.     l2.place(x=385, y=13)
  119.  
  120.     # Creating the login username text
  121.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  122.     lgnt1.place(x=40, y=140)
  123.  
  124.     # Creating the username login entry form
  125.     global user
  126.     user = Entry(root, textvariable=username_var, width=20)
  127.     user.place(x=140, y=140)
  128.  
  129.     # Creating the login password text
  130.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  131.     lgnt2.place(x=40, y=180)
  132.  
  133.     # Creating the password entry form
  134.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  135.     pswd.place(x=140, y=180)
  136.  
  137.     # Creating the submit button
  138.     submit = Button(root, text="SUBMIT", command=stud_lgn)
  139.     submit.place(x=130, y=220)
  140.  
  141.     root.mainloop()
  142.  
  143. """
  144. The stud_lgn() function is used to check for the username and password in the database and make further movements
  145. Tt uses the global username_var and password_var for checking the values
  146. It used .get() method to get the str() return of the entered value from the report
  147. Then that value is used to validate the student using mysql connection
  148.  
  149. If the entered value is correct then this window proceeds into stud_home()
  150. If not then the window will show an error message stating 'Cannot find such a user with the given username and passweord. Please retry'
  151. """
  152. def stud_lgn():
  153.     name = username_var.get()
  154.     passw = passw_var.get()
  155.  
  156.     cur.execute(
  157.         "SELECT * FROM STUDENTS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  158.  
  159.     a = cur.fetchone()
  160.  
  161.     global L
  162.     L = []
  163.  
  164.     if a !=None and len(a) != 0:
  165.         for k in a:
  166.             L.append(k)
  167.  
  168.         root.destroy()
  169.         stud_home()
  170.        
  171.     else:
  172.         messagebox.showerror(
  173.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  174.  
  175.     username_var.set("")
  176.     passw_var.set("")
  177.  
  178. """
  179. This function is the student' home page
  180. This is proceeded from the stud_lgn(), if the entered credentials are correct then the student proceeds into the home page
  181. The home page consists of 4 buttons namely, PROFILE, LEAVE ENTRY, ACADEMICS AND LOGOUT
  182. When the user clicks on the button it proceeds into the next page
  183. """
  184. def stud_home():
  185.     # Setting window appearance mode
  186.     customtkinter.set_appearance_mode("dark")
  187.    
  188.     # Setting default color theme
  189.     customtkinter.set_default_color_theme("dark-blue")
  190.  
  191.     # Creating the student home window
  192.     shw = customtkinter.CTk()
  193.  
  194.     shw.title("STUDENT HOME")
  195.     shw.geometry("941x619")
  196.     shw.resizable(0, 0)
  197.     shw.iconbitmap("./ico/student.ico")
  198.  
  199.     # Creating the background variable for the window
  200.     bg = PhotoImage(file="./img/stud_home.png")
  201.    
  202.     # Setting up the background
  203.     l1 = Label(shw, image=bg)
  204.     l1.place(x=0, y=0)
  205.  
  206.     # Creating a label for user details
  207.     l2 = Label(shw, text="WELCOME TO STUDENT HOME", font=("Consolas", 20, "bold"), fg="white", bg="black")
  208.     l2.pack()
  209.  
  210.     # Creating image variable for icon Images
  211.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile.png").resize((20, 20), Image.Resampling.LANCZOS))
  212.     lv_entry = ImageTk.PhotoImage(Image.open("./icons/leave_entry.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  213.     logout = ImageTk.PhotoImage(Image.open("./icons/logout.png").resize((20, 20), Image.Resampling.LANCZOS))
  214.     academics = ImageTk.PhotoImage(Image.open("./icons/academics.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  215.  
  216.     # Student Profile button
  217.     b1 = customtkinter.CTkButton(master=shw, width=150, height=40, text="PROFILE", image=std_profile, command=lambda: stud_profile(shw, L))
  218.     b1.place(x=775, y=90)
  219.  
  220.     # Leave Entry Button
  221.     b2 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LEAVE ENTRY", image=lv_entry, command=lambda: stud_leave_entry(shw))
  222.     b2.place(x=775, y=190)
  223.  
  224.     # Academics Button
  225.     b3 = customtkinter.CTkButton(master=shw, text="ACADEMICS", width=150, height=40, image = academics, command=lambda: stud_academics(shw))
  226.     b3.place(x=775, y=290)
  227.  
  228.     # Logout Button
  229.     b4 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LOGOUT", image=logout, command=lambda: stud_logout(shw))
  230.     b4.place(x=775, y=390)
  231.     shw.mainloop()
  232.  
  233. """
  234. This function is the logout function
  235. This function destroys the current window and then moves back to the home page
  236. """
  237. def stud_logout(window):
  238.     window.destroy()
  239.     home()
  240.  
  241. """
  242. This function is used to show the progress of the student in the academic year
  243. It consists of test papaers and exam marks
  244. The student may click and chose the subject from the combobox
  245. The student may then click and chose the exam progression or test paper progression and the chart displays on the tkinter window
  246. """
  247. def stud_academics(window):
  248.     window.destroy()
  249.  
  250. #def stud_academics() -> None:
  251.     customtkinter.set_appearance_mode("dark")
  252.     customtkinter.set_default_color_theme("dark-blue")
  253.  
  254.     # Creating text variable for subject, examination
  255.     global sub_var
  256.     global examintaion
  257.  
  258.     # Creating academics window
  259.     saw = customtkinter.CTk()
  260.     saw.geometry("1280x585")
  261.     saw.resizable(0,0)
  262.  
  263.     sub_var = StringVar()
  264.     examination_var = StringVar()
  265.    
  266.     saw.title("STUDENT ACADEMICS")
  267.     saw.iconbitmap("./ico/stud_academics.ico")
  268.  
  269.     # Creating background image variable
  270.     bg = ImageTk.PhotoImage(Image.open("./icons/academics.jpg").resize((1280, 720), Image.Resampling.LANCZOS))
  271.  
  272.     # Creating background image label
  273.     l1 = customtkinter.CTkLabel(master=saw, image=bg, bg_color="black")
  274.     l1.place(x=0, y=0)
  275.  
  276.     # Creating the subject text label
  277.     l2 = customtkinter.CTkLabel(master=saw, text="SUBJECT", text_font=("Consolas", 20, "bold"))
  278.     l2.place(x=1070, y=40)
  279.  
  280.     # Getting student stream from database
  281.     stream = L[6]
  282.  
  283.     # Creating combobox
  284.     cb1 = customtkinter.CTkComboBox(master=saw)
  285.  
  286.     if stream == "computer science":
  287.         cb1["values"] = ["Computer Science", "Maths", "Chemistry", "Physics, English"]
  288.    
  289.     elif stream == "bio maths":
  290.         cb1["values"] = ["Biology", "Maths", "Chemistry", "Physics", "English"]
  291.  
  292.     elif stream == "bio psychology":
  293.         cb1["values"] = ["Biology", "Psychology", "Chemistry", "Physics", "English"]
  294.  
  295.     elif stream == "commerce computer":
  296.         cb1["values"] = ["Commerce", "Bussiness", "Economics", "Accountancy", "Computer Science"]
  297.  
  298.     elif stream == "commerce ip":
  299.         cb1["values"] = ["Commerce", "Bussiness", "Economics", "Accountancy", "IP"]
  300.  
  301.     elif stream == "commerce maths":
  302.         cb1["values"] = ["Commerce", "Bussiness", "Economics", "Accountancy", "Maths"]
  303.  
  304.     cb1.place(x=1070, y=60)
  305.  
  306.     saw.mainloop()
  307.  
  308. """
  309. This is the stud_profile function
  310. It accepts 2 arguments
  311. They accepted positional arguments are parentwindow and the list of the login details of the student
  312. Firstly, the function destroys the parent window and opens up a new window
  313. In the profile window the student is shown the profile icon, name, class and dob
  314. """
  315. def stud_profile(pw, L):
  316.     # Destroying parent window
  317.     pw.destroy()
  318.  
  319.     customtkinter.set_appearance_mode("light")
  320.     customtkinter.set_default_color_theme("dark-blue")
  321.    
  322.     spw = customtkinter.CTk()
  323.     spw.resizable(0,0)
  324.  
  325.     spw.title("STUDENT PROFILE")
  326.     spw.iconbitmap("./ico/student.ico")
  327.  
  328.     l1 = customtkinter.CTkLabel(master=spw, text="STUDENT PROFILE", text_font=("Consolas", 20, "italic"))
  329.     l1.pack()
  330.  
  331.     # Creating the image variable for the profile picture image
  332.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile1.jpg").resize((200, 200), Image.Resampling.LANCZOS))
  333.    
  334.     # Creating the label icon
  335.     l1 = customtkinter.CTkLabel(master=spw, image=std_profile, bg_color="white")
  336.     l1.place(x=200, y=70)
  337.  
  338.     # Placing name
  339.     name = "Name: "
  340.     l2 = customtkinter.CTkLabel(master=spw, text=name+L[1])
  341.     l2.place(x=210, y=250)
  342.  
  343.     # Placing class
  344.     grade = "Class: "
  345.     l3 = customtkinter.CTkLabel(master=spw, text=grade+str(L[4])+' '+L[5])
  346.     l3.place(x=210, y=270)
  347.  
  348.     # Placing DOB
  349.     dob = "DOB: "
  350.     l4 = customtkinter.CTkLabel(master=spw, text=dob+str(L[7]))
  351.     l4.place(x=210, y=290)
  352.  
  353.     # Placing go back to student home
  354.     b1 = customtkinter.CTkButton(master=spw, text="GO BACK TO PREVIOUS WINDOW", command=lambda: go_back_to_prev(spw))
  355.     b1.place(x=172, y=330)
  356.  
  357.     spw.mainloop()
  358.  
  359. """
  360. This function is student leave entry function
  361. This accepts the parent window as its argument
  362. Firsty, this function destroyes the parent window
  363.  
  364. The new window has two date entry namely startdate and enddate
  365. It also has the reason box where the parent has to enter the reason for the leave
  366. """
  367. def stud_leave_entry(win):
  368.     win.destroy()
  369.  
  370.     slew = customtkinter.CTk()
  371.     slew.resizable(0,0)
  372.     slew.iconbitmap("./ico/student.ico")
  373.     slew.title("STUDENT LEAVE ENTRY")
  374.  
  375.     # Creating start date, end date and reason text variables
  376.     global start_date
  377.     global end_date
  378.     global reason
  379.  
  380.     start_date = StringVar()
  381.     end_date = StringVar()
  382.     reason = StringVar()
  383.  
  384.     # Creating the heading
  385.     l1 = customtkinter.CTkLabel(master=slew, text="LEAVE ENTRY", text_font=("times new roman", 21, "bold"))
  386.     l1.pack()
  387.  
  388.     # Creating the start date text label
  389.     l1 = customtkinter.CTkLabel(master=slew, text="START DATE", text_font=("Consolas", 12, "bold"))
  390.     l1.place(x=30, y=90)
  391.  
  392.     # Creating start date button
  393.     global b1
  394.     b1 = DateEntry(master=slew, date_pattern="yyyy-mm-dd",textvariable=start_date)
  395.     b1.place(x=250, y=100)
  396.  
  397.     l2 = customtkinter.CTkLabel(master=slew, text="END DATE", text_font=("Consolas", 12, "bold"))
  398.     l2.place(x=30, y=160)
  399.  
  400.     global b2
  401.     b2 = DateEntry(master=slew, date_pattern="yyyy-mm-dd", textvariable=end_date)
  402.     b2.place(x=250, y=170)
  403.  
  404.     l3 = customtkinter.CTkLabel(master=slew, text="REASON", text_font=("Consolas", 12, "bold"))
  405.     l3.place(x=30, y=220)
  406.  
  407.     global b3
  408.     b3 = customtkinter.CTkEntry(master=slew, textvariable=reason, width=300)
  409.     b3.place(x=190, y=220)
  410.  
  411.     # Creating the submit button
  412.     submit = customtkinter.CTkButton(master=slew, text="Submit", command=lambda: stud_leave_entry_submit(slew))
  413.     submit.place(x=190, y=270)
  414.  
  415.     # Creating go back to student home
  416.     b4 = customtkinter.CTkButton(master=slew, text="GO BACK TO PREVIOUS WINDOW", command=lambda: go_back_to_prev(slew))
  417.     b4.place(x=190, y=320)
  418.  
  419.     slew.mainloop()
  420.  
  421. """
  422. This function is called when the submit button in the stud_leave_entry() function is clicked
  423. It then used .get() method to extract the str() values from the input
  424. The inputted values are then passed into mysql and are stored in the stud_leave table
  425. """
  426. def stud_leave_entry_submit(window):
  427.     sd = start_date.get()
  428.     ed = end_date.get()
  429.     rs = reason.get()
  430.  
  431.     cur.execute("SELECT * FROM STUD_LEAVE")
  432.     a = cur.rowcount
  433.  
  434.     cur.execute("INSERT INTO STUD_LEAVE(NAME, CLASS, DIVISION, STARTDATE, ENDDATE, REASON) VALUES (%s, %s, %s, %s, %s, %s)", (L[1], L[4], L[5], sd, ed, rs))  
  435.  
  436.     cur.execute("SELECT * FROM STUD_LEAVE")
  437.     b = cur.rowcount
  438.  
  439.     if b == a + 1:
  440.         messagebox.showinfo("SUCCESSFUL", "LEAVE ENTRY SUCCESSFULLY INSERTED")
  441.  
  442.     else:
  443.         print("Some connection with leave entry, Please approach the developer as soon as possible")
  444.  
  445.     time.sleep(1)
  446.  
  447.     go_back_to_prev(window)
  448.  
  449. """"
  450. This function is used to close the current window and go back to the student home window
  451. """
  452. def go_back_to_prev(pw):
  453.     pw.destroy()
  454.     stud_home()
  455.  
  456. def teacher_lgn_btn(window):
  457.     # Killing the previous window and moving to the student window
  458.     window.destroy()
  459.  
  460.     # Making the tkinter window global
  461.     global root
  462.  
  463.     # Creating new window
  464.     root = Tk()
  465.  
  466.     root.title("TEACHER LOGIN")
  467.     root.geometry("960x600")
  468.     root.resizable(0, 0)
  469.     root.iconbitmap("./ico/teacher.ico")
  470.  
  471.     # Creating String Vars
  472.     global username_var
  473.     global passw_var
  474.     username_var = StringVar()
  475.     passw_var = StringVar()
  476.  
  477.     # Creating the background image variable
  478.     bg = PhotoImage(file="./img/all_lgn.png")
  479.  
  480.     # Creating the label background
  481.     l1 = Label(root, image=bg)
  482.     l1.place(x=0, y=0)
  483.  
  484.     # Creating student login text
  485.     l2 = Label(root, text="TEACHER LOGIN", background="#413E91",
  486.                font=("times new roman", 20, "bold"), fg="black")
  487.     l2.place(x=385, y=13)
  488.  
  489.     # Creating the login username text
  490.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  491.     lgnt1.place(x=40, y=140)
  492.  
  493.     # Creating the username login entry form
  494.     global user
  495.     user = Entry(root, textvariable=username_var, width=20)
  496.     user.place(x=140, y=140)
  497.  
  498.     # Creating the login password text
  499.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  500.     lgnt2.place(x=40, y=180)
  501.  
  502.     # Creating the password entry form
  503.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  504.     pswd.place(x=140, y=180)
  505.  
  506.     # Creating the submit button
  507.     submit = Button(root, text="SUBMIT", command=teacher_lgn)
  508.     submit.place(x=130, y=220)
  509.  
  510.     root.mainloop()
  511.  
  512.  
  513. def teacher_lgn():
  514.     name = username_var.get()
  515.     passw = passw_var.get()
  516.  
  517.     cur.execute(
  518.         "SELECT * FROM TEACHERS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  519.  
  520.     a = cur.fetchone()
  521.  
  522.     global L
  523.     L = []
  524.  
  525.     if a != None and len(a) != 0:
  526.         for k in a:
  527.             L.append(k)
  528.  
  529.         root.destroy()
  530.         teacher_home()
  531.        
  532.     else:
  533.         messagebox.showerror(
  534.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  535.  
  536.     username_var.set("")
  537.     passw_var.set("")
  538.  
  539. def teacher_home():
  540.     # Setting window appearance mode
  541.     customtkinter.set_appearance_mode("dark")
  542.    
  543.     # Setting default color theme
  544.     customtkinter.set_default_color_theme("dark-blue")
  545.  
  546.     # Creating the student home window
  547.     shw = customtkinter.CTk()
  548.  
  549.     shw.title("TEACHER HOME")
  550.     shw.geometry("941x619")
  551.     shw.resizable(0, 0)
  552.     shw.iconbitmap("./ico/teacher.ico")
  553.  
  554.     # Creating the background variable for the window
  555.     bg = ImageTk.PhotoImage(Image.open("./img/teacher_home.jpg").resize((941, 619), Image.Resampling.LANCZOS))
  556.    
  557.     # Setting up the background
  558.     l1 = Label(shw, image=bg)
  559.     l1.place(x=0, y=0)
  560.  
  561.     # Creating a label for user details
  562.     l2 = Label(shw, text="WELCOME TO TEACHER HOME", font=("Consolas", 20, "bold"), fg="white", bg="black")
  563.     l2.pack()
  564.  
  565.     # Creating image variable for icon Images
  566.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile.png").resize((20, 20), Image.Resampling.LANCZOS))
  567.     lv_entry = ImageTk.PhotoImage(Image.open("./icons/leave_entry.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  568.     logout = ImageTk.PhotoImage(Image.open("./icons/logout.png").resize((20, 20), Image.Resampling.LANCZOS))
  569.     academics = ImageTk.PhotoImage(Image.open("./icons/academics.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  570.  
  571.     # Teacher Profile button
  572.     b1 = customtkinter.CTkButton(master=shw, width=150, height=40, text="PROFILE", image=std_profile, command=lambda: stud_profile(shw, L))
  573.     b1.place(x=775, y=90)
  574.  
  575.     # Leave Entry Button
  576.     b2 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LEAVE ENTRY", image=lv_entry, command=lambda: stud_leave_entry(shw))
  577.     b2.place(x=775, y=190)
  578.  
  579.     # Academics Button
  580.     #b3 = customtkinter.CTkButton(master=shw, text="ACADEMICS", width=150, height=40, image = academics, command=lambda: stud_academics(shw))
  581.     #b3.place(x=775, y=290)
  582.  
  583.     # Logout Button
  584.     b4 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LOGOUT", image=logout, command=lambda: stud_logout(shw))
  585.     b4.place(x=775, y=390)
  586.     shw.mainloop()
  587.  
  588.  
  589. def staff_lgn_btn(window):
  590.     # Killing the previous window and moving to the student window
  591.     window.destroy()
  592.  
  593.     # Making the tkinter window global
  594.     global root
  595.  
  596.     # Creating new window
  597.     root = Tk()
  598.  
  599.     root.title("STAFF LOGIN")
  600.     root.geometry("960x600")
  601.     root.resizable(0, 0)
  602.     root.iconbitmap("./ico/staff.ico")
  603.  
  604.     # Creating String Vars
  605.     global username_var
  606.     global passw_var
  607.     username_var = StringVar()
  608.     passw_var = StringVar()
  609.  
  610.     # Creating the background image variable
  611.     bg = PhotoImage(file="./img/all_lgn.png")
  612.  
  613.     # Creating the label background
  614.     l1 = Label(root, image=bg)
  615.     l1.place(x=0, y=0)
  616.  
  617.     # Creating student login text
  618.     l2 = Label(root, text="STAFF LOGIN", background="#413E91",
  619.                font=("times new roman", 20, "bold"), fg="black")
  620.     l2.place(x=385, y=13)
  621.  
  622.     # Creating the login username text
  623.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  624.     lgnt1.place(x=40, y=140)
  625.  
  626.     # Creating the username login entry form
  627.     global user
  628.     user = Entry(root, textvariable=username_var, width=20)
  629.     user.place(x=140, y=140)
  630.  
  631.     # Creating the login password text
  632.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  633.     lgnt2.place(x=40, y=180)
  634.  
  635.     # Creating the password entry form
  636.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  637.     pswd.place(x=140, y=180)
  638.  
  639.     # Creating the submit button
  640.     submit = Button(root, text="SUBMIT", command=staff_lgn)
  641.     submit.place(x=130, y=220)
  642.  
  643.     root.mainloop()
  644.  
  645.  
  646. def staff_lgn():
  647.     name = username_var.get()
  648.     passw = passw_var.get()
  649.  
  650.     cur.execute(
  651.         "SELECT * FROM STAFF WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  652.  
  653.     a = cur.fetchone()
  654.  
  655.     global L
  656.     L = []
  657.  
  658.     if a !=None and len(a) != 0:
  659.         for k in a:
  660.             L.append(k)
  661.  
  662.         root.destroy()
  663.         staff_home()
  664.        
  665.     else:
  666.         messagebox.showerror(
  667.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  668.  
  669.     username_var.set("")
  670.     passw_var.set("")
  671.  
  672.  
  673. def admin_lgn_btn(window):
  674.     # Killing the previous window and moving to the student window
  675.     window.destroy()
  676.  
  677.     # Making the tkinter window global
  678.     global root
  679.  
  680.     # Creating new window
  681.     root = Tk()
  682.  
  683.     root.title("ADMIN LOGIN")
  684.     root.geometry("960x600")
  685.     root.resizable(0, 0)
  686.     root.iconbitmap("./ico/admin.ico")
  687.  
  688.     # Creating String Vars
  689.     global username_var
  690.     global passw_var
  691.     username_var = StringVar()
  692.     passw_var = StringVar()
  693.  
  694.     # Creating the background image variable
  695.     bg = PhotoImage(file="./img/all_lgn.png")
  696.  
  697.     # Creating the label background
  698.     l1 = Label(root, image=bg)
  699.     l1.place(x=0, y=0)
  700.  
  701.     # Creating student login text
  702.     l2 = Label(root, text="ADMIN LOGIN", background="#413E91",
  703.                font=("times new roman", 20, "bold"), fg="black")
  704.     l2.place(x=385, y=13)
  705.  
  706.     # Creating the login username text
  707.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  708.     lgnt1.place(x=40, y=140)
  709.  
  710.     # Creating the username login entry form
  711.     global user
  712.     user = Entry(root, textvariable=username_var, width=20)
  713.     user.place(x=140, y=140)
  714.  
  715.     # Creating the login password text
  716.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  717.     lgnt2.place(x=40, y=180)
  718.  
  719.     # Creating the password entry form
  720.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  721.     pswd.place(x=140, y=180)
  722.  
  723.     # Creating the submit button
  724.     submit = Button(root, text="SUBMIT", command=admin_lgn)
  725.     submit.place(x=130, y=220)
  726.  
  727.     root.mainloop()
  728.  
  729.  
  730. def admin_lgn():
  731.     name = username_var.get()
  732.     passw = passw_var.get()
  733.  
  734.     cur.execute(
  735.         "SELECT * FROM ADMIN WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  736.  
  737.     a = cur.fetchone()
  738.  
  739.     global L
  740.     L = []
  741.  
  742.     if a !=None and len(a) != 0:
  743.         for k in a:
  744.             L.append(k)
  745.  
  746.         root.destroy()
  747.         admin_home()
  748.        
  749.     else:
  750.         messagebox.showerror(
  751.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  752.  
  753.     username_var.set("")
  754.     passw_var.set("")
  755.  
  756. def staff_home():
  757.     pass
  758.  
  759. def admin_home():
  760.     pass
  761.  
  762. if __name__ == "__main__":
  763.     home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement