Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import messagebox
- import mysql.connector as mc
- from tkinter import *
- # MySQL Objects and connection string
- cnx = mc.connect(host="localhost", user="alen", password="alen", database="school")
- cur = cnx.cursor()
- cnx.autocommit = True
- """
- 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)
- """
- def home():
- window = Tk()
- window.title("SCHOOL MANAGEMENT SYSTEM")
- window.geometry("960x606")
- window.resizable(0,0)
- window.iconbitmap("./ico/school.ico")
- # Creating background image variable
- bg = PhotoImage(file="./img/login.png")
- # Creating the background label
- l1 = Label(window, image=bg)
- l1.place(x=0, y=0)
- # Creating the login text
- l2 = Label(window, text="LOGIN", font=("times new roman", 20, "bold"), bg="#184800", fg="#ff007f")
- l2.place(x=441, y=23)
- # Creating the student button
- l3 = Button(window, text="STUDENT", width=15, font=("times new roman",10, "bold"), command=lambda: stud_lgn_btn(window))
- l3.place(x=435, y=100)
- # Creating the teacher button
- l4 = Button(window, text="TEACHER", width=15, font=("times new roman", 10, "bold"))
- l4.place(x=435, y=140)
- # Creating the staff button
- l5 = Button(window, text="STAFF", width=15, font=("times new roman", 10, "bold"))
- l5.place(x=435, y=180)
- # Creating the admin button
- l6 = Button(window, text="ADMIN", width=15, font=("times new roman",10, "bold"))
- l6.place(x=435, y=220)
- window.mainloop()
- def stud_lgn_btn(window):
- # Killing the previous window and moving to the student window
- window.destroy()
- # Making the tkinter window global
- global root
- # Creating new window
- root = Tk()
- root.title("STUDENT LOGIN")
- root.geometry("960x600")
- root.resizable(0,0)
- root.iconbitmap("./ico/student.ico")
- #Creating String Vars
- global username_var
- global passw_var
- username_var = StringVar()
- passw_var = StringVar()
- # Creating the background image variable
- bg = PhotoImage(file="./img/student_lgn.png")
- # Creating the label background
- l1 = Label(root, image=bg)
- l1.place(x=0, y=0)
- # Creating student login text
- l2 = Label(root, text="STUDENT LOGIN", background="#413E91", font=("times new roman", 20, "bold"), fg="black")
- l2.place(x=385, y=13)
- # Creating the login username text
- lgnt1 = Label(root, text="USERNAME", font=("times new roman", 10, "bold"))
- lgnt1.place(x=40, y=140)
- # Creating the username login entry form
- global user
- user = Entry(root, textvariable=username_var, width=20)
- user.place(x=140, y=140)
- # Creating the login password text
- lgnt2 = Label(root, text="PASSWORD", font=("times new roman", 10, "bold"))
- lgnt2.place(x=40, y=180)
- # Creating the password entry form
- pswd = Entry(root, textvariable=passw_var, width=20, show="*")
- pswd.place(x=140, y=180)
- # Creating the submit button
- submit = Button(root, text="SUBMIT", command=stud_lgn)
- submit.place(x=130, y=220)
- root.mainloop()
- def stud_lgn():
- name = username_var.get()
- passw = passw_var.get()
- cur.execute("SELECT * FROM STUDENTS WHERE USERNAME=%s AND PASSWORD=%s", (name, passw))
- a = cur.fetchall()
- if any(a):
- root.destroy()
- stud_home()
- else:
- messagebox.showerror("User nor found", "Cannot find such a user with the given username and password. Please retry")
- username_var.set("")
- passw_var.set("")
- def stud_home():
- # Creating the student home window
- shw = Tk()
- shw.title("STUDENT HOME")
- shw.iconbitmap("./ico/student.ico")
- shw.geometry("960x521")
- shw.resizable(0,0)
- # Creating the background image variable
- bg = PhotoImage("./img/stud_home.png")
- # Creating the label background
- l1 = Label(shw, image=bg)
- l1.pack()
- if __name__ == "__main__":
- home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement