Advertisement
ALENTL

main.py

Oct 31st, 2022
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 31.68 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 time module to set program delay
  18. import time
  19.  
  20. # MySQL Objects and connection string
  21. cnx = mc.connect(host="localhost", user="alen",
  22.                  password="alen", database="school")
  23. #Setting buffered to True to get rid of unread results found error
  24. cur = cnx.cursor(buffered=True)
  25. cnx.autocommit = True
  26.  
  27. """
  28. 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)
  29. """
  30. def home():
  31.     window = Tk()
  32.     window.title("SCHOOL MANAGEMENT SYSTEM")
  33.     window.geometry("960x606")
  34.     window.resizable(0, 0)
  35.     window.iconbitmap("./ico/school.ico")
  36.  
  37.     # Creating background image variable
  38.     bg = PhotoImage(file="./img/login.png")
  39.  
  40.     # Creating the background label
  41.     l1 = Label(window, image=bg)
  42.     l1.place(x=0, y=0)
  43.  
  44.     # Creating the login text
  45.     l2 = Label(window, text="LOGIN", font=(
  46.         "times new roman", 20, "bold"), bg="#184800", fg="#ff007f")
  47.     l2.place(x=441, y=23)
  48.  
  49.     # Creating the student button
  50.     l3 = Button(window, text="STUDENT", width=15, font=(
  51.         "times new roman", 10, "bold"), command=lambda: stud_lgn_btn(window))
  52.     l3.place(x=435, y=100)
  53.  
  54.     # Creating the teacher button
  55.     l4 = Button(window, text="TEACHER", width=15, font=(
  56.         "times new roman", 10, "bold"), command=lambda: teacher_lgn_btn(window))
  57.     l4.place(x=435, y=140)
  58.  
  59.     # Creating the staff button
  60.     l5 = Button(window, text="STAFF", width=15, font=(
  61.         "times new roman", 10, "bold"), command=lambda: staff_lgn_btn(window))
  62.     l5.place(x=435, y=180)
  63.  
  64.     window.mainloop()
  65.  
  66. """
  67. The stud_lgn_btn() is a function that changes the window from home window to student login widnow.
  68. It accepts the parent window as it's param and destroys the window
  69. This page consists of username and password entry and a submit button
  70. The username and password are passed on to the username_var and password_var text variables respectively
  71. Then the submit button calls on the command stud_lgn()
  72. """
  73. def stud_lgn_btn(window):
  74.     # Killing the previous window and moving to the student window
  75.     window.destroy()
  76.  
  77.     # Making the tkinter window global
  78.     global root
  79.  
  80.     # Creating new window
  81.     root = Tk()
  82.  
  83.     root.title("STUDENT LOGIN")
  84.     root.geometry("960x600")
  85.     root.resizable(0, 0)
  86.     root.iconbitmap("./ico/student.ico")
  87.  
  88.     # Creating String Vars
  89.     global username_var
  90.     global passw_var
  91.     username_var = StringVar()
  92.     passw_var = StringVar()
  93.  
  94.     # Creating the background image variable
  95.     bg = PhotoImage(file="./img/all_lgn.png")
  96.  
  97.     # Creating the label background
  98.     l1 = Label(root, image=bg)
  99.     l1.place(x=0, y=0)
  100.  
  101.     # Creating student login text
  102.     l2 = Label(root, text="STUDENT LOGIN", background="#413E91",
  103.                font=("times new roman", 20, "bold"), fg="black")
  104.     l2.place(x=385, y=13)
  105.  
  106.     # Creating the login username text
  107.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  108.     lgnt1.place(x=40, y=140)
  109.  
  110.     # Creating the username login entry form
  111.     global user
  112.     user = Entry(root, textvariable=username_var, width=20)
  113.     user.place(x=140, y=140)
  114.  
  115.     # Creating the login password text
  116.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  117.     lgnt2.place(x=40, y=180)
  118.  
  119.     # Creating the password entry form
  120.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  121.     pswd.place(x=140, y=180)
  122.  
  123.     # Creating the submit button
  124.     submit = Button(root, text="SUBMIT", command=stud_lgn)
  125.     submit.place(x=130, y=220)
  126.  
  127.     root.mainloop()
  128.  
  129. """
  130. The stud_lgn() function is used to check for the username and password in the database and make further movements
  131. Tt uses the global username_var and password_var for checking the values
  132. It used .get() method to get the str() return of the entered value from the report
  133. Then that value is used to validate the student using mysql connection
  134.  
  135. If the entered value is correct then this window proceeds into stud_home()
  136. If not then the window will show an error message stating 'Cannot find such a user with the given username and passweord. Please retry'
  137. """
  138. def stud_lgn():
  139.     name = username_var.get()
  140.     passw = passw_var.get()
  141.  
  142.     cur.execute(
  143.         "SELECT * FROM STUDENTS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  144.  
  145.     a = cur.fetchone()
  146.  
  147.     global L
  148.     L = []
  149.  
  150.     if a !=None and len(a) != 0:
  151.         for k in a:
  152.             L.append(k)
  153.  
  154.         root.destroy()
  155.         stud_home()
  156.        
  157.     else:
  158.         messagebox.showerror(
  159.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  160.  
  161.     username_var.set("")
  162.     passw_var.set("")
  163.  
  164. """
  165. This function is the student' home page
  166. This is proceeded from the stud_lgn(), if the entered credentials are correct then the student proceeds into the home page
  167. The home page consists of 4 buttons namely, PROFILE, LEAVE ENTRY, ACADEMICS AND LOGOUT
  168. When the user clicks on the button it proceeds into the next page
  169. """
  170. def stud_home():
  171.     # Setting window appearance mode
  172.     customtkinter.set_appearance_mode("dark")
  173.    
  174.     # Setting default color theme
  175.     customtkinter.set_default_color_theme("dark-blue")
  176.  
  177.     # Creating the student home window
  178.     shw = customtkinter.CTk()
  179.  
  180.     shw.title("STUDENT HOME")
  181.     shw.geometry("941x619")
  182.     shw.resizable(0, 0)
  183.     shw.iconbitmap("./ico/student.ico")
  184.  
  185.     # Creating the background variable for the window
  186.     bg = PhotoImage(file="./img/stud_home.png")
  187.    
  188.     # Setting up the background
  189.     l1 = Label(shw, image=bg)
  190.     l1.place(x=0, y=0)
  191.  
  192.     # Creating a label for user details
  193.     l2 = Label(shw, text="WELCOME TO STUDENT HOME", font=("Consolas", 20, "bold"), fg="white", bg="black")
  194.     l2.pack()
  195.  
  196.     # Creating image variable for icon Images
  197.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile.png").resize((20, 20), Image.Resampling.LANCZOS))
  198.     lv_entry = ImageTk.PhotoImage(Image.open("./icons/leave_entry.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  199.     logout = ImageTk.PhotoImage(Image.open("./icons/logout.png").resize((20, 20), Image.Resampling.LANCZOS))
  200.  
  201.     # Student Profile button
  202.     b1 = customtkinter.CTkButton(master=shw, width=150, height=40, text="PROFILE", image=std_profile, command=lambda: stud_profile(shw, L))
  203.     b1.place(x=775, y=90)
  204.  
  205.     # Leave Entry Button
  206.     b2 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LEAVE ENTRY", image=lv_entry, command=lambda: stud_leave_entry(shw))
  207.     b2.place(x=775, y=190)
  208.    
  209.     # Logout Button
  210.     b4 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LOGOUT", image=logout, command=lambda: all_logout(shw))
  211.     b4.place(x=775, y=290)
  212.     shw.mainloop()
  213.  
  214. """
  215. This function is the logout function
  216. This function destroys the current window and then moves back to the home page
  217. """
  218. def all_logout(window):
  219.     window.destroy()
  220.     home()
  221.  
  222. """
  223. This is the stud_profile function
  224. It accepts 2 arguments
  225. They accepted positional arguments are parentwindow and the list of the login details of the student
  226. Firstly, the function destroys the parent window and opens up a new window
  227. In the profile window the student is shown the profile icon, name, class and dob
  228. """
  229. def stud_profile(pw, L):
  230.     # Destroying parent window
  231.     pw.destroy()
  232.  
  233.     customtkinter.set_appearance_mode("light")
  234.     customtkinter.set_default_color_theme("dark-blue")
  235.    
  236.     spw = customtkinter.CTk()
  237.     spw.resizable(0,0)
  238.  
  239.     spw.title("STUDENT PROFILE")
  240.     spw.iconbitmap("./ico/student.ico")
  241.  
  242.     l1 = customtkinter.CTkLabel(master=spw, text="STUDENT PROFILE", text_font=("Consolas", 20, "italic"))
  243.     l1.pack()
  244.  
  245.     # Creating the image variable for the profile picture image
  246.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile1.jpg").resize((200, 200), Image.Resampling.LANCZOS))
  247.    
  248.     # Creating the label icon
  249.     l1 = customtkinter.CTkLabel(master=spw, image=std_profile, bg_color="white")
  250.     l1.place(x=200, y=70)
  251.  
  252.     # Placing name
  253.     name = "Name: "
  254.     l2 = customtkinter.CTkLabel(master=spw, text=name+L[1])
  255.     l2.place(x=210, y=250)
  256.  
  257.     # Placing class
  258.     grade = "Class: "
  259.     l3 = customtkinter.CTkLabel(master=spw, text=grade+str(L[4])+' '+L[5])
  260.     l3.place(x=210, y=270)
  261.  
  262.     # Placing DOB
  263.     dob = "DOB: "
  264.     l4 = customtkinter.CTkLabel(master=spw, text=dob+str(L[7]))
  265.     l4.place(x=210, y=290)
  266.  
  267.     # Placing go back to student home
  268.     b1 = customtkinter.CTkButton(master=spw, text="GO BACK TO PREVIOUS WINDOW", command=lambda: go_back_to_prev(spw))
  269.     b1.place(x=172, y=330)
  270.  
  271.     spw.mainloop()
  272.  
  273. """
  274. This function is student leave entry function
  275. This accepts the parent window as its argument
  276. Firsty, this function destroyes the parent window
  277.  
  278. The new window has two date entry namely startdate and enddate
  279. It also has the reason box where the parent has to enter the reason for the leave
  280. """
  281. def stud_leave_entry(win):
  282.     win.destroy()
  283.  
  284.     slew = customtkinter.CTk()
  285.     slew.resizable(0,0)
  286.     slew.iconbitmap("./ico/student.ico")
  287.     slew.title("STUDENT LEAVE ENTRY")
  288.  
  289.     # Creating start date, end date and reason text variables
  290.     global start_date
  291.     global end_date
  292.     global reason
  293.  
  294.     start_date = StringVar()
  295.     end_date = StringVar()
  296.     reason = StringVar()
  297.  
  298.     # Creating the heading
  299.     l1 = customtkinter.CTkLabel(master=slew, text="LEAVE ENTRY", text_font=("times new roman", 21, "bold"))
  300.     l1.pack()
  301.  
  302.     # Creating the start date text label
  303.     l1 = customtkinter.CTkLabel(master=slew, text="START DATE", text_font=("Consolas", 12, "bold"))
  304.     l1.place(x=30, y=90)
  305.  
  306.     # Creating start date button
  307.     global b1
  308.     b1 = DateEntry(master=slew, date_pattern="yyyy-mm-dd",textvariable=start_date)
  309.     b1.place(x=250, y=100)
  310.  
  311.     l2 = customtkinter.CTkLabel(master=slew, text="END DATE", text_font=("Consolas", 12, "bold"))
  312.     l2.place(x=30, y=160)
  313.  
  314.     global b2
  315.     b2 = DateEntry(master=slew, date_pattern="yyyy-mm-dd", textvariable=end_date)
  316.     b2.place(x=250, y=170)
  317.  
  318.     l3 = customtkinter.CTkLabel(master=slew, text="REASON", text_font=("Consolas", 12, "bold"))
  319.     l3.place(x=30, y=220)
  320.  
  321.     global b3
  322.     b3 = customtkinter.CTkEntry(master=slew, textvariable=reason, width=300)
  323.     b3.place(x=190, y=220)
  324.  
  325.     # Creating the submit button
  326.     submit = customtkinter.CTkButton(master=slew, text="Submit", command=lambda: stud_leave_entry_submit(slew))
  327.     submit.place(x=190, y=270)
  328.  
  329.     # Creating go back to student home
  330.     b4 = customtkinter.CTkButton(master=slew, text="GO BACK TO PREVIOUS WINDOW", command=lambda: go_back_to_prev(slew))
  331.     b4.place(x=190, y=320)
  332.  
  333.     slew.mainloop()
  334.  
  335. """
  336. This function is called when the submit button in the stud_leave_entry() function is clicked
  337. It then used .get() method to extract the str() values from the input
  338. The inputted values are then passed into mysql and are stored in the stud_leave table
  339. """
  340. def stud_leave_entry_submit(window):
  341.     sd = start_date.get()
  342.     ed = end_date.get()
  343.     rs = reason.get()
  344.  
  345.     cur.execute("SELECT * FROM STUD_LEAVE")
  346.     a = cur.rowcount
  347.  
  348.     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))  
  349.  
  350.     cur.execute("SELECT * FROM STUD_LEAVE")
  351.     b = cur.rowcount
  352.  
  353.     if b == a + 1:
  354.         messagebox.showinfo("SUCCESSFUL", "LEAVE ENTRY SUCCESSFULLY INSERTED")
  355.  
  356.     else:
  357.         print("Some connection with leave entry, Please approach the developer as soon as possible")
  358.  
  359.     time.sleep(1)
  360.  
  361.     go_back_to_prev(window)
  362.  
  363. """"
  364. This function is used to close the current window and go back to the student home window
  365. """
  366. def go_back_to_prev(pw):
  367.     pw.destroy()
  368.     stud_home()
  369.  
  370. def teacher_lgn_btn(window):
  371.     # Killing the previous window and moving to the student window
  372.     window.destroy()
  373.  
  374.     # Making the tkinter window global
  375.     global root
  376.  
  377.     # Creating new window
  378.     root = Tk()
  379.  
  380.     root.title("TEACHER LOGIN")
  381.     root.geometry("960x600")
  382.     root.resizable(0, 0)
  383.     root.iconbitmap("./ico/teacher.ico")
  384.  
  385.     # Creating String Vars
  386.     global username_var
  387.     global passw_var
  388.     username_var = StringVar()
  389.     passw_var = StringVar()
  390.  
  391.     # Creating the background image variable
  392.     bg = PhotoImage(file="./img/all_lgn.png")
  393.  
  394.     # Creating the label background
  395.     l1 = Label(root, image=bg)
  396.     l1.place(x=0, y=0)
  397.  
  398.     # Creating student login text
  399.     l2 = Label(root, text="TEACHER LOGIN", background="#413E91",
  400.                font=("times new roman", 20, "bold"), fg="black")
  401.     l2.place(x=385, y=13)
  402.  
  403.     # Creating the login username text
  404.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  405.     lgnt1.place(x=40, y=140)
  406.  
  407.     # Creating the username login entry form
  408.     global user
  409.     user = Entry(root, textvariable=username_var, width=20)
  410.     user.place(x=140, y=140)
  411.  
  412.     # Creating the login password text
  413.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  414.     lgnt2.place(x=40, y=180)
  415.  
  416.     # Creating the password entry form
  417.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  418.     pswd.place(x=140, y=180)
  419.  
  420.     # Creating the submit button
  421.     submit = Button(root, text="SUBMIT", command=teacher_lgn)
  422.     submit.place(x=130, y=220)
  423.  
  424.     root.mainloop()
  425.  
  426.  
  427. def teacher_lgn():
  428.     name = username_var.get()
  429.     passw = passw_var.get()
  430.  
  431.     cur.execute(
  432.         "SELECT * FROM TEACHERS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  433.  
  434.     a = cur.fetchone()
  435.  
  436.     global L
  437.     L = []
  438.  
  439.     if a != None and len(a) != 0:
  440.         for k in a:
  441.             L.append(k)
  442.  
  443.         root.destroy()
  444.         teacher_home()
  445.        
  446.     else:
  447.         messagebox.showerror(
  448.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  449.  
  450.     username_var.set("")
  451.     passw_var.set("")
  452.  
  453. def teacher_home():
  454.     # Setting window appearance mode
  455.     customtkinter.set_appearance_mode("dark")
  456.    
  457.     # Setting default color theme
  458.     customtkinter.set_default_color_theme("dark-blue")
  459.  
  460.     # Creating the student home window
  461.     shw = customtkinter.CTk()
  462.  
  463.     shw.title("TEACHER HOME")
  464.     shw.geometry("941x619")
  465.     shw.resizable(0, 0)
  466.     shw.iconbitmap("./ico/teacher.ico")
  467.  
  468.     # Creating the background variable for the window
  469.     bg = ImageTk.PhotoImage(Image.open("./img/teacher_home.jpg").resize((941, 619), Image.Resampling.LANCZOS))
  470.    
  471.     # Setting up the background
  472.     l1 = Label(shw, image=bg)
  473.     l1.place(x=0, y=0)
  474.  
  475.     # Creating a label for user details
  476.     l2 = Label(shw, text="WELCOME TO TEACHER HOME", font=("Consolas", 20, "bold"), fg="white", bg="black")
  477.     l2.pack()
  478.  
  479.     # Creating image variable for icon Images
  480.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile.png").resize((20, 20), Image.Resampling.LANCZOS))
  481.     lv_entry = ImageTk.PhotoImage(Image.open("./icons/leave_entry.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  482.     logout = ImageTk.PhotoImage(Image.open("./icons/logout.png").resize((20, 20), Image.Resampling.LANCZOS))
  483.     search_stud = ImageTk.PhotoImage(Image.open("./icons/search_stud.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  484.    
  485.     # Teacher Profile button
  486.     b1 = customtkinter.CTkButton(master=shw, width=150, height=40, text="PROFILE", image=std_profile, command=lambda: teacher_profile(shw, L))
  487.     b1.place(x=775, y=90)
  488.  
  489.     # Leave Entry Button
  490.     b2 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LEAVE ENTRY", image=lv_entry, command=lambda: teacher_leave_entry(shw))
  491.     b2.place(x=775, y=190)
  492.  
  493.     # Student Search Button
  494.     b3 = customtkinter.CTkButton(master=shw, width=150, height=40, text="SEARCH STUDENT", image=search_stud, command=lambda: search_student(shw))
  495.     b3.place(x=775, y=290)
  496.  
  497.     # Logout Button
  498.     b4 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LOGOUT", image=logout, command=lambda: all_logout(shw))
  499.     b4.place(x=775, y=390)
  500.     shw.mainloop()
  501.  
  502. def teacher_profile(pw, L):
  503.     # Destroying parent window
  504.     pw.destroy()
  505.  
  506.     customtkinter.set_appearance_mode("light")
  507.     customtkinter.set_default_color_theme("dark-blue")
  508.    
  509.     spw = customtkinter.CTk()
  510.     spw.resizable(0,0)
  511.  
  512.     spw.title("TEACHER PROFILE")
  513.     spw.iconbitmap("./ico/teacher.ico")
  514.  
  515.     l1 = customtkinter.CTkLabel(master=spw, text="TEACHER PROFILE", text_font=("Consolas", 20, "italic"))
  516.     l1.pack()
  517.  
  518.     # Creating the image variable for the profile picture image
  519.     tch_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile1.jpg").resize((200, 200), Image.Resampling.LANCZOS))
  520.    
  521.     # Creating the label icon
  522.     l1 = customtkinter.CTkLabel(master=spw, image=tch_profile, bg_color="white")
  523.     l1.place(x=200, y=70)
  524.  
  525.     # Placing name
  526.     name = "Name: "
  527.     l2 = customtkinter.CTkLabel(master=spw, text=name+L[1])
  528.     l2.place(x=210, y=250)
  529.  
  530.     # Placing class
  531.     grade = "Subject: "
  532.     l3 = customtkinter.CTkLabel(master=spw, text=grade+str(L[4]))
  533.     l3.place(x=210, y=270)
  534.  
  535.     # Placing DOB
  536.     dob = "DOB: "
  537.     l4 = customtkinter.CTkLabel(master=spw, text=dob+str(L[5]))
  538.     l4.place(x=210, y=290)
  539.  
  540.     # Placing go back to student home
  541.     b1 = customtkinter.CTkButton(master=spw, text="GO BACK TO PREVIOUS WINDOW", command=lambda: teacher_go_back_to_prev(spw))
  542.     b1.place(x=172, y=330)
  543.  
  544.     spw.mainloop()
  545.  
  546. def teacher_go_back_to_prev(cw):
  547.     cw.destroy()
  548.     teacher_home()
  549.  
  550. def teacher_leave_entry(win):
  551.     win.destroy()
  552.  
  553.     slew = customtkinter.CTk()
  554.     slew.resizable(0,0)
  555.     slew.iconbitmap("./ico/student.ico")
  556.     slew.title("TEACHER LEAVE ENTRY")
  557.  
  558.     # Creating start date, end date and reason text variables
  559.     global start_date
  560.     global end_date
  561.     global reason
  562.  
  563.     start_date = StringVar()
  564.     end_date = StringVar()
  565.     reason = StringVar()
  566.  
  567.     # Creating the heading
  568.     l1 = customtkinter.CTkLabel(master=slew, text="LEAVE ENTRY", text_font=("times new roman", 21, "bold"))
  569.     l1.pack()
  570.  
  571.     # Creating the start date text label
  572.     l1 = customtkinter.CTkLabel(master=slew, text="START DATE", text_font=("Consolas", 12, "bold"))
  573.     l1.place(x=30, y=90)
  574.  
  575.     # Creating start date button
  576.     global b1
  577.     b1 = DateEntry(master=slew, date_pattern="yyyy-mm-dd",textvariable=start_date)
  578.     b1.place(x=250, y=100)
  579.  
  580.     l2 = customtkinter.CTkLabel(master=slew, text="END DATE", text_font=("Consolas", 12, "bold"))
  581.     l2.place(x=30, y=160)
  582.  
  583.     global b2
  584.     b2 = DateEntry(master=slew, date_pattern="yyyy-mm-dd", textvariable=end_date)
  585.     b2.place(x=250, y=170)
  586.  
  587.     l3 = customtkinter.CTkLabel(master=slew, text="REASON", text_font=("Consolas", 12, "bold"))
  588.     l3.place(x=30, y=220)
  589.  
  590.     global b3
  591.     b3 = customtkinter.CTkEntry(master=slew, textvariable=reason, width=300)
  592.     b3.place(x=190, y=220)
  593.  
  594.     # Creating the submit button
  595.     submit = customtkinter.CTkButton(master=slew, text="Submit", command=lambda: teacher_leave_entry_submit(slew))
  596.     submit.place(x=190, y=270)
  597.  
  598.     # Creating go back to student home
  599.     b4 = customtkinter.CTkButton(master=slew, text="GO BACK TO PREVIOUS WINDOW", command=lambda: go_back_to_prev(slew))
  600.     b4.place(x=190, y=320)
  601.  
  602.     slew.mainloop()
  603.  
  604. def teacher_leave_entry_submit(window):
  605.     sd = start_date.get()
  606.     ed = end_date.get()
  607.     rs = reason.get()
  608.  
  609.     cur.execute("SELECT * FROM TEACHER_LEAVE")
  610.     a = cur.rowcount
  611.  
  612.     cur.execute("INSERT INTO TEACHER_LEAVE(NAME, STARTDATE, ENDDATE, REASON) VALUES (%s, %s, %s, %s)", (L[1], sd, ed, rs))  
  613.  
  614.     cur.execute("SELECT * FROM TEACHER_LEAVE")
  615.     b = cur.rowcount
  616.  
  617.     if b == a + 1:
  618.         messagebox.showinfo("SUCCESSFUL", "LEAVE ENTRY SUCCESSFULLY INSERTED")
  619.  
  620.     else:
  621.         print("Some connection with leave entry, Please approach the developer as soon as possible")
  622.  
  623.     time.sleep(1)
  624.  
  625.     teacher_go_back_to_prev(window)
  626.  
  627. def search_student(window):
  628.     window.destroy()
  629.  
  630.     # Setting window appearance mode
  631.     customtkinter.set_appearance_mode("dark")
  632.    
  633.     # Setting default color theme
  634.     customtkinter.set_default_color_theme("dark-blue")
  635.  
  636.     ssw = customtkinter.CTk()
  637.     ssw.resizable(0,0)
  638.     ssw.title("SEARCH STUDENT")
  639.  
  640.     global stud_name_var
  641.  
  642.     stud_name_var = customtkinter.StringVar()
  643.  
  644.     l1 = customtkinter.CTkLabel(master=ssw, text="STUDENT LIST", text_font=("Consolas", 21, "bold"))
  645.     l1.pack()
  646.  
  647.     l2 = customtkinter.CTkLabel(master=ssw, text="STUDENT NAME: ")
  648.     l2.place(x=40, y=40)
  649.  
  650.     e1 = customtkinter.CTkEntry(master=ssw, width=200, textvariable=stud_name_var)
  651.     e1.place(x=200, y=40)
  652.  
  653.     submit = customtkinter.CTkButton(master=ssw, text="SUBMIT", command=lambda: search_student_name())
  654.     submit.place(x=150, y=80)
  655.    
  656.     ssw.mainloop()
  657.  
  658. def search_student_name():
  659.     name = stud_name_var.get()
  660.  
  661.     cur.execute("SELECT * FROM STUDENTS WHERE NAME=%s", (name,))
  662.    
  663.     global A
  664.     a = cur.fetchone()
  665.  
  666.     A = []
  667.  
  668.     if a != None:
  669.         for k in a:
  670.             A.append(k)
  671.  
  672.     display_stud_details()
  673.  
  674. def display_stud_details():
  675.     snw = customtkinter.CTk()
  676.     snw.title("STUDENT DATA")
  677.  
  678.     i = 0
  679.  
  680.     for k in range(len(A)):
  681.         e = customtkinter.CTkLabel(master=snw, width=10, text=A[k], borderwidth=2, relief="ridge", anchor="w")
  682.         e.grid(row=i, column=k)
  683.  
  684.     snw.mainloop()
  685.  
  686. def search_teachers(window):
  687.     window.destroy()
  688.  
  689.     # Setting window appearance mode
  690.     customtkinter.set_appearance_mode("dark")
  691.    
  692.     # Setting default color theme
  693.     customtkinter.set_default_color_theme("dark-blue")
  694.  
  695.     ssw = customtkinter.CTk()
  696.     ssw.resizable(0,0)
  697.     ssw.title("SEARCH TEACHER")
  698.  
  699.     global tch_name_var
  700.  
  701.     tch_name_var = customtkinter.StringVar()
  702.  
  703.     l1 = customtkinter.CTkLabel(master=ssw, text="TEACHER LIST", text_font=("Consolas", 21, "bold"))
  704.     l1.pack()
  705.  
  706.     l2 = customtkinter.CTkLabel(master=ssw, text="STUDENT NAME: ")
  707.     l2.place(x=40, y=40)
  708.  
  709.     e1 = customtkinter.CTkEntry(master=ssw, width=200, textvariable=tch_name_var)
  710.     e1.place(x=200, y=40)
  711.  
  712.     submit = customtkinter.CTkButton(master=ssw, text="SUBMIT", command=lambda: search_teacher_name())
  713.     submit.place(x=150, y=80)
  714.  
  715.     ssw.mainloop()
  716.  
  717. def search_teacher_name():
  718.     name = tch_name_var.get()
  719.  
  720.     cur.execute("SELECT * FROM TEACHERS WHERE NAME=%s", (name,))
  721.    
  722.     global A
  723.     a = cur.fetchone()
  724.  
  725.     A = []
  726.  
  727.     if a != None:
  728.         for k in a:
  729.             A.append(k)
  730.  
  731.     display_teacher_details()
  732.  
  733. def display_teacher_details():
  734.     snw = customtkinter.CTk()
  735.     snw.title("TEACHER DATA")
  736.  
  737.     i = 0
  738.  
  739.     for k in range(len(A)):
  740.         e = customtkinter.CTkLabel(master=snw, width=10, text=A[k], borderwidth=2, relief="ridge", anchor="w")
  741.         e.grid(row=i, column=k)
  742.  
  743.     snw.mainloop()
  744.  
  745.  
  746. def staff_lgn_btn(window):
  747.     # Killing the previous window and moving to the student window
  748.     window.destroy()
  749.  
  750.     # Making the tkinter window global
  751.     global root
  752.  
  753.     # Creating new window
  754.     root = Tk()
  755.  
  756.     root.title("STAFF LOGIN")
  757.     root.geometry("960x600")
  758.     root.resizable(0, 0)
  759.     root.iconbitmap("./ico/staff.ico")
  760.  
  761.     # Creating String Vars
  762.     global username_var
  763.     global passw_var
  764.     username_var = StringVar()
  765.     passw_var = StringVar()
  766.  
  767.     # Creating the background image variable
  768.     bg = PhotoImage(file="./img/all_lgn.png")
  769.  
  770.     # Creating the label background
  771.     l1 = Label(root, image=bg)
  772.     l1.place(x=0, y=0)
  773.  
  774.     # Creating student login text
  775.     l2 = Label(root, text="STAFF LOGIN", background="#413E91",
  776.                font=("times new roman", 20, "bold"), fg="black")
  777.     l2.place(x=385, y=13)
  778.  
  779.     # Creating the login username text
  780.     lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
  781.     lgnt1.place(x=40, y=140)
  782.  
  783.     # Creating the username login entry form
  784.     global user
  785.     user = Entry(root, textvariable=username_var, width=20)
  786.     user.place(x=140, y=140)
  787.  
  788.     # Creating the login password text
  789.     lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
  790.     lgnt2.place(x=40, y=180)
  791.  
  792.     # Creating the password entry form
  793.     pswd = Entry(root, textvariable=passw_var, width=20, show="*")
  794.     pswd.place(x=140, y=180)
  795.  
  796.     # Creating the submit button
  797.     submit = Button(root, text="SUBMIT", command=staff_lgn)
  798.     submit.place(x=130, y=220)
  799.  
  800.     root.mainloop()
  801.  
  802.  
  803. def staff_lgn():
  804.     name = username_var.get()
  805.     passw = passw_var.get()
  806.  
  807.     cur.execute(
  808.         "SELECT * FROM STAFF WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
  809.  
  810.     a = cur.fetchone()
  811.  
  812.     global L
  813.     L = []
  814.  
  815.     if a !=None and len(a) != 0:
  816.         for k in a:
  817.             L.append(k)
  818.  
  819.         root.destroy()
  820.         staff_home()
  821.        
  822.     else:
  823.         messagebox.showerror(
  824.             "User nor found", "Cannot find such a user with the given username and password. Please retry")
  825.  
  826.     username_var.set("")
  827.     passw_var.set("")
  828.  
  829. def staff_home():
  830.     # Setting window appearance mode
  831.     customtkinter.set_appearance_mode("dark")
  832.    
  833.     # Setting default color theme
  834.     customtkinter.set_default_color_theme("dark-blue")
  835.  
  836.     # Creating the student home window
  837.     shw = customtkinter.CTk()
  838.  
  839.     shw.title("TEACHER HOME")
  840.     shw.geometry("941x619")
  841.     shw.resizable(0, 0)
  842.     shw.iconbitmap("./ico/teacher.ico")
  843.  
  844.     # Creating the background variable for the window
  845.     bg = ImageTk.PhotoImage(Image.open("./img/teacher_home.jpg").resize((941, 619), Image.Resampling.LANCZOS))
  846.    
  847.     # Setting up the background
  848.     l1 = Label(shw, image=bg)
  849.     l1.place(x=0, y=0)
  850.  
  851.     # Creating a label for user details
  852.     l2 = Label(shw, text="WELCOME TO STAFF HOME", font=("Consolas", 20, "bold"), fg="white", bg="black")
  853.     l2.pack()
  854.  
  855.     # Creating image variable for icon Images
  856.     std_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile.png").resize((20, 20), Image.Resampling.LANCZOS))
  857.     lv_entry = ImageTk.PhotoImage(Image.open("./icons/leave_entry.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  858.     logout = ImageTk.PhotoImage(Image.open("./icons/logout.png").resize((20, 20), Image.Resampling.LANCZOS))
  859.     search = ImageTk.PhotoImage(Image.open("./icons/search_stud.jpg").resize((20, 20), Image.Resampling.LANCZOS))
  860.    
  861.     # Staff Profile button
  862.     b1 = customtkinter.CTkButton(master=shw, width=150, height=40, text="PROFILE", image=std_profile, command=lambda: staff_profile(shw, L))
  863.     b1.place(x=775, y=90)
  864.  
  865.     # Leave Entry Button
  866.     b2 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LEAVE ENTRY", image=lv_entry, command=lambda: staff_leave_entry(shw))
  867.     b2.place(x=775, y=190)
  868.  
  869.     # Student Name Checkup
  870.     b3 = customtkinter.CTkButton(master=shw, width=150, height=40, text="STUDENT SEARCH", image=search, command=lambda: search_student(shw))
  871.     b3.place(x=775, y=290)
  872.  
  873.     # Teacher Name Checkup
  874.     b5 = customtkinter.CTkButton(master=shw, width=150, height=40, text="TEACHER SEARCH", image=search, command=lambda: search_teachers(shw))
  875.     b5.place(x=775, y=390)
  876.  
  877.     # Logout Button
  878.     b5 = customtkinter.CTkButton(master=shw, width=150, height=40, text="LOGOUT", image=logout, command=lambda: all_logout(shw))
  879.     b5.place(x=775, y=490)
  880.     shw.mainloop()
  881.  
  882. def staff_profile(pw, L):
  883.     # Destroying parent window
  884.     pw.destroy()
  885.  
  886.     customtkinter.set_appearance_mode("light")
  887.     customtkinter.set_default_color_theme("dark-blue")
  888.    
  889.     spw = customtkinter.CTk()
  890.     spw.resizable(0,0)
  891.  
  892.     spw.title("STAFF PROFILE")
  893.     spw.iconbitmap("./ico/staff.ico")
  894.  
  895.     l1 = customtkinter.CTkLabel(master=spw, text="STAFF PROFILE", text_font=("Consolas", 20, "italic"))
  896.     l1.pack()
  897.  
  898.     # Creating the image variable for the profile picture image
  899.     stf_profile = ImageTk.PhotoImage(Image.open("./icons/std_profile1.jpg").resize((200, 200), Image.Resampling.LANCZOS))
  900.    
  901.     # Creating the label icon
  902.     l1 = customtkinter.CTkLabel(master=spw, image=stf_profile, bg_color="white")
  903.     l1.place(x=200, y=70)
  904.  
  905.     # Placing name
  906.     name = "Name: "
  907.     l2 = customtkinter.CTkLabel(master=spw, text=name+L[1])
  908.     l2.place(x=210, y=250)
  909.  
  910.     # Placing work
  911.     grade = "Work: "
  912.     l3 = customtkinter.CTkLabel(master=spw, text=grade+str(L[4]))
  913.     l3.place(x=210, y=270)
  914.  
  915.     # Placing DOB
  916.     dob = "DOB: "
  917.     l4 = customtkinter.CTkLabel(master=spw, text=dob+str(L[5]))
  918.     l4.place(x=210, y=290)
  919.  
  920.     # Placing go back to student home
  921.     b1 = customtkinter.CTkButton(master=spw, text="GO BACK TO PREVIOUS WINDOW", command=lambda: staff_go_back_to_prev(spw))
  922.     b1.place(x=172, y=330)
  923.  
  924.     spw.mainloop()
  925.  
  926. def staff_go_back_to_prev(cw):
  927.     cw.destroy()
  928.     staff_home()
  929.  
  930. def staff_leave_entry(win):
  931.     win.destroy()
  932.  
  933.     slew = customtkinter.CTk()
  934.     slew.resizable(0,0)
  935.     slew.iconbitmap("./ico/student.ico")
  936.     slew.title("STAFF LEAVE ENTRY")
  937.  
  938.     # Creating start date, end date and reason text variables
  939.     global start_date
  940.     global end_date
  941.     global reason
  942.  
  943.     start_date = StringVar()
  944.     end_date = StringVar()
  945.     reason = StringVar()
  946.  
  947.     # Creating the heading
  948.     l1 = customtkinter.CTkLabel(master=slew, text="LEAVE ENTRY", text_font=("times new roman", 21, "bold"))
  949.     l1.pack()
  950.  
  951.     # Creating the start date text label
  952.     l1 = customtkinter.CTkLabel(master=slew, text="START DATE", text_font=("Consolas", 12, "bold"))
  953.     l1.place(x=30, y=90)
  954.  
  955.     # Creating start date button
  956.     global b1
  957.     b1 = DateEntry(master=slew, date_pattern="yyyy-mm-dd",textvariable=start_date)
  958.     b1.place(x=250, y=100)
  959.  
  960.     l2 = customtkinter.CTkLabel(master=slew, text="END DATE", text_font=("Consolas", 12, "bold"))
  961.     l2.place(x=30, y=160)
  962.  
  963.     global b2
  964.     b2 = DateEntry(master=slew, date_pattern="yyyy-mm-dd", textvariable=end_date)
  965.     b2.place(x=250, y=170)
  966.  
  967.     l3 = customtkinter.CTkLabel(master=slew, text="REASON", text_font=("Consolas", 12, "bold"))
  968.     l3.place(x=30, y=220)
  969.  
  970.     global b3
  971.     b3 = customtkinter.CTkEntry(master=slew, textvariable=reason, width=300)
  972.     b3.place(x=190, y=220)
  973.  
  974.     # Creating the submit button
  975.     submit = customtkinter.CTkButton(master=slew, text="Submit", command=lambda: staff_leave_entry_submit(slew))
  976.     submit.place(x=190, y=270)
  977.  
  978.     # Creating go back to student home
  979.     b4 = customtkinter.CTkButton(master=slew, text="GO BACK TO PREVIOUS WINDOW", command=lambda: staff_go_back_to_prev(slew))
  980.     b4.place(x=190, y=320)
  981.  
  982.     slew.mainloop()
  983.  
  984. def staff_leave_entry_submit(window):
  985.     sd = start_date.get()
  986.     ed = end_date.get()
  987.     rs = reason.get()
  988.  
  989.     cur.execute("SELECT * FROM STAFF_LEAVE")
  990.     a = cur.rowcount
  991.  
  992.     cur.execute("INSERT INTO STAFF_LEAVE(NAME, STARTDATE, ENDDATE, REASON) VALUES (%s, %s, %s, %s)", (L[1], sd, ed, rs))  
  993.  
  994.     cur.execute("SELECT * FROM STAFF_LEAVE")
  995.     b = cur.rowcount
  996.  
  997.     if b == a + 1:
  998.         messagebox.showinfo("SUCCESSFUL", "LEAVE ENTRY SUCCESSFULLY INSERTED")
  999.  
  1000.     else:
  1001.         print("Some connection error with leave entry, Please approach the developer as soon as possible")
  1002.  
  1003.     time.sleep(1)
  1004.  
  1005.     staff_go_back_to_prev(window)
  1006.  
  1007. if __name__ == "__main__":
  1008.     home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement