Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import ctypes
- class UniversityCMS:
- #adminUsername = "Admin"
- #adminPassword = "Admin"
- studentUsernames = ["16045206", "16045235", "16045232"]
- studentPasswords = ["Apple", "Pear", "Orange"]
- teacherUsernames = ["p16042352", "p1321032", "p1230432"]
- teacherPasswords = ["Web", "Internet", "Browser"]
- def __init__(self, master):
- # Frames act as seperate containers for the buttons and the labels/entry
- loginFrame = Frame(master)
- loginFrame.pack()
- buttonFrame = Frame(master)
- buttonFrame.pack()
- master.minsize(width=300,height=110)
- self.parent = root
- # Login label and entry box
- self.var_statusLabel = StringVar()
- self.statusLabel= Label(loginFrame, textvariable = self.var_statusLabel, fg="green").grid(row=0, column=1)
- self.loginLabel = Label(loginFrame, text="Username:").grid(row=1,column=0)
- self.var_username = StringVar()
- self.input_username = Entry(loginFrame, textvariable = self.var_username).grid(row=1,column=1)
- # Password label and entry box
- self.passwordLabel = Label(loginFrame, text="Password:").grid(row=2,column=0)
- self.var_password = StringVar()
- self.input_password = Entry(loginFrame, textvariable=self.var_password, show="*").grid(row=2,column=1)
- # Login and exit buttons
- self.exitButton = Button(buttonFrame, text="Exit", command=master.destroy, fg="red").pack(side=LEFT,padx=2, pady=2)
- self.loginButton = Button(buttonFrame, text="Login", command=self.hubUI, fg="blue").pack(side=LEFT,padx=2, pady=2)
- self.loginButton
- def hubUI(self):
- for student in range(len(self.studentUsernames)):
- if self.studentUsernames[student] == self.var_username.get() and self.studentPasswords[student] == self.var_password.get():
- ctypes.windll.user32.MessageBoxW(0, "Welcome student. You have successfully logged in.", "Logged in - Student", 0)
- self.studentUI()
- for teacher in range(len(self.teacherUsernames)):
- if self.teacherUsernames[teacher] == self.var_username.get() and self.teacherPasswords[teacher] == self.var_password.get():
- ctypes.windll.user32.MessageBoxW(0, "Welcome. You have successfully logged in.",
- "Logged in - Lecturer", 0)
- self.teacherUI()
- def studentUI(self):
- self.var_statusLabel.set("LOGGED IN: " + self.var_username.get())
- self.var_username.set("")
- self.var_password.set("")
- self.studentScreen = Toplevel(master=self.parent)
- self.studentScreen.resizable(0, 0)
- self.studentScreen.minsize(300, 300)
- self.studentScreen.title("University CMS - Student Page")
- studentFrame = Frame(self.studentScreen)
- studentFrame.pack()
- self.studentScreen.titleLabel = Label(studentFrame, text="Student Page", font=("Helvetica", 16)).pack(
- pady=5)
- self.studentScreen.gradesButton = Button(studentFrame, text="View Your Grades", fg="blue", height=5,
- width=30)
- self.studentScreen.gradesButton.pack()
- self.studentScreen.otherButton = Button(studentFrame, text="...", fg="blue", height=5, width=30)
- self.studentScreen.otherButton.pack(pady=5)
- self.studentScreen.exitButton = Button(studentFrame, text="Exit", fg="red", height=2, width=30,
- command=root.destroy)
- self.studentScreen.exitButton.pack()
- def teacherUI(self):
- self.var_statusLabel.set("LOGGED IN: " + self.var_username.get())
- self.var_username.set("")
- self.var_password.set("")
- self.teacherScreen = Toplevel(master=self.parent)
- self.teacherScreen.resizable(0, 0)
- self.teacherScreen.minsize(300, 300)
- self.teacherScreen.title("University CMS - Lecturer Page")
- studentFrame = Frame(self.teacherScreen)
- studentFrame.pack()
- self.teacherScreen.titleLabel = Label(studentFrame, text="Lecturer Page", font=("Helvetica", 16)).pack(
- pady=5)
- self.teacherScreen.gradesButton = Button(studentFrame, text="View Student Grades", fg="blue", height=5,
- width=30)
- self.teacherScreen.gradesButton.pack()
- self.teacherScreen.otherButton = Button(studentFrame, text="...", fg="blue", height=5, width=30)
- self.teacherScreen.otherButton.pack(pady=5)
- self.teacherScreen.exitButton = Button(studentFrame, text="Back to Login", fg="red", height=2, width=30,
- command=self.teacherScreen.destroy)
- self.teacherScreen.exitButton.pack()
- root = Tk()
- root.resizable(0,0)
- root.title("University CMS: Login")
- cms = UniversityCMS(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement