Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. from tkinter import *
  2. import ctypes
  3.  
  4. class UniversityCMS:
  5.  
  6. #adminUsername = "Admin"
  7. #adminPassword = "Admin"
  8.  
  9. studentUsernames = ["16045206", "16045235", "16045232"]
  10. studentPasswords = ["Apple", "Pear", "Orange"]
  11.  
  12. teacherUsernames = ["p16042352", "p1321032", "p1230432"]
  13. teacherPasswords = ["Web", "Internet", "Browser"]
  14.  
  15. def __init__(self, master):
  16. # Frames act as seperate containers for the buttons and the labels/entry
  17. loginFrame = Frame(master)
  18. loginFrame.pack()
  19. buttonFrame = Frame(master)
  20. buttonFrame.pack()
  21. master.minsize(width=300,height=110)
  22. self.parent = root
  23.  
  24. # Login label and entry box
  25. self.var_statusLabel = StringVar()
  26. self.statusLabel= Label(loginFrame, textvariable = self.var_statusLabel, fg="green").grid(row=0, column=1)
  27. self.loginLabel = Label(loginFrame, text="Username:").grid(row=1,column=0)
  28. self.var_username = StringVar()
  29. self.input_username = Entry(loginFrame, textvariable = self.var_username).grid(row=1,column=1)
  30.  
  31. # Password label and entry box
  32. self.passwordLabel = Label(loginFrame, text="Password:").grid(row=2,column=0)
  33. self.var_password = StringVar()
  34. self.input_password = Entry(loginFrame, textvariable=self.var_password, show="*").grid(row=2,column=1)
  35.  
  36. # Login and exit buttons
  37. self.exitButton = Button(buttonFrame, text="Exit", command=master.destroy, fg="red").pack(side=LEFT,padx=2, pady=2)
  38. self.loginButton = Button(buttonFrame, text="Login", command=self.hubUI, fg="blue").pack(side=LEFT,padx=2, pady=2)
  39. self.loginButton
  40.  
  41. def hubUI(self):
  42. for student in range(len(self.studentUsernames)):
  43. if self.studentUsernames[student] == self.var_username.get() and self.studentPasswords[student] == self.var_password.get():
  44. ctypes.windll.user32.MessageBoxW(0, "Welcome student. You have successfully logged in.", "Logged in - Student", 0)
  45. self.studentUI()
  46. for teacher in range(len(self.teacherUsernames)):
  47. if self.teacherUsernames[teacher] == self.var_username.get() and self.teacherPasswords[teacher] == self.var_password.get():
  48. ctypes.windll.user32.MessageBoxW(0, "Welcome. You have successfully logged in.",
  49. "Logged in - Lecturer", 0)
  50. self.teacherUI()
  51.  
  52. def studentUI(self):
  53. self.var_statusLabel.set("LOGGED IN: " + self.var_username.get())
  54. self.var_username.set("")
  55. self.var_password.set("")
  56. self.studentScreen = Toplevel(master=self.parent)
  57. self.studentScreen.resizable(0, 0)
  58. self.studentScreen.minsize(300, 300)
  59. self.studentScreen.title("University CMS - Student Page")
  60. studentFrame = Frame(self.studentScreen)
  61. studentFrame.pack()
  62.  
  63. self.studentScreen.titleLabel = Label(studentFrame, text="Student Page", font=("Helvetica", 16)).pack(
  64. pady=5)
  65. self.studentScreen.gradesButton = Button(studentFrame, text="View Your Grades", fg="blue", height=5,
  66. width=30)
  67. self.studentScreen.gradesButton.pack()
  68. self.studentScreen.otherButton = Button(studentFrame, text="...", fg="blue", height=5, width=30)
  69. self.studentScreen.otherButton.pack(pady=5)
  70. self.studentScreen.exitButton = Button(studentFrame, text="Exit", fg="red", height=2, width=30,
  71. command=root.destroy)
  72. self.studentScreen.exitButton.pack()
  73.  
  74. def teacherUI(self):
  75. self.var_statusLabel.set("LOGGED IN: " + self.var_username.get())
  76. self.var_username.set("")
  77. self.var_password.set("")
  78. self.teacherScreen = Toplevel(master=self.parent)
  79. self.teacherScreen.resizable(0, 0)
  80. self.teacherScreen.minsize(300, 300)
  81. self.teacherScreen.title("University CMS - Lecturer Page")
  82. studentFrame = Frame(self.teacherScreen)
  83. studentFrame.pack()
  84.  
  85. self.teacherScreen.titleLabel = Label(studentFrame, text="Lecturer Page", font=("Helvetica", 16)).pack(
  86. pady=5)
  87. self.teacherScreen.gradesButton = Button(studentFrame, text="View Student Grades", fg="blue", height=5,
  88. width=30)
  89. self.teacherScreen.gradesButton.pack()
  90. self.teacherScreen.otherButton = Button(studentFrame, text="...", fg="blue", height=5, width=30)
  91. self.teacherScreen.otherButton.pack(pady=5)
  92. self.teacherScreen.exitButton = Button(studentFrame, text="Back to Login", fg="red", height=2, width=30,
  93. command=self.teacherScreen.destroy)
  94. self.teacherScreen.exitButton.pack()
  95.  
  96. root = Tk()
  97. root.resizable(0,0)
  98. root.title("University CMS: Login")
  99. cms = UniversityCMS(root)
  100. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement