Guest User

Untitled

a guest
Feb 10th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import tkinter
  2. # Creating the getDetails function.
  3. # Gets the username and opens the file of the username.
  4. # If the file doesn't exit / username is invalid,
  5. # An error message is shown.
  6. def getDetails():
  7. # Makes the variable "username" global.
  8. # Can be accessed by other functions later.
  9. global username
  10. username = username_entry.get()
  11. try:
  12. usernameFile = open(username + ".txt", 'r+')
  13. usernameFileLine = usernameFile.readlines()
  14. # Gets the password the user input.
  15. password = password_entry.get()
  16. username_error.pack_forget()
  17. # Checks if the password is correct.
  18. # If not, an error message is shown.
  19. if password == usernameFileLine[0]:
  20. # Function to open the optionUI.
  21. optionMenu()
  22. # Closes the loginUI.
  23. loginUI.destroy()
  24. else:
  25. password_error.pack()
  26. # Checks if the username is invalid.
  27. except FileNotFoundError:
  28. # Packs the error message for invalid username.
  29. username_error.pack()
  30.  
  31.  
  32. # Creates the main loginUI.
  33. # Don't need a function for this.
  34. loginUI = tkinter.Tk()
  35. loginUI.title("loginUI")
  36. loginUI.geometry("400x200")
  37. loginUI.configure(background="#a1dbcd")
  38. # Creating all the labels and entries for the loginUI.
  39. def optionMenu():
  40. # Checks if the adminUI is open.
  41.  
  42. # Makes optionUI global.
  43. # Can be closed later in another function.
  44. global optionUI
  45. optionUI = tkinter.Tk()
  46. optionUI.title("Main Menu")
  47. optionUI.geometry("400x200")
  48. optionUI.configure(background="#FFFF99")
  49. # Creates a blank line.
  50. blank = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
  51. view_Details = tkinter.Button(optionUI, text='VIEW DETAILS', font="Arial 10 bold", command=viewDetails).pack()
  52. blank2 = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
  53. changePasswordoptionUI = tkinter.Button(optionUI, text='CHANGE PASSWORD', font="Arial 10 bold", command=changePassword).pack()
  54. blank3 = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
  55. # Opens the admin file.
  56. admin = open('admins.txt', 'r+')
  57. adminUIMenuButton = tkinter.Button(optionUI, text='ADMINISTRATOR MENU', font="Arial 10 bold", command=adminMenu)
  58. contactUIMenuButton = tkinter.Button(optionUI, text='CONTACT ADMINISTRATOR', font="Arial 10 bold", command=contactMenu)
  59. lines = admin.readlines()
  60. # Checks if the user is an admin.
  61. if username in lines:
  62. # Packs the adminUI button.
  63. adminUIMenuButton.pack()
  64. optionUI.mainloop()
  65. else:
  66. # Packs the contactUI button.
  67. contactUIMenuButton.pack()
  68. optionUI.mainloop()
  69.  
  70.  
  71. blank_label = tkinter.Label(loginUI, text="", bg="#a1dbcd")
  72. username_label = tkinter.Label(loginUI, text="USERNAME", font="Arial 8 bold", bg="#a1dbcd")
  73. username_entry = tkinter.Entry(loginUI)
  74. password_label = tkinter.Label(loginUI, text="PASSWORD", font="Arial 8 bold", bg="#a1dbcd")
  75. password_entry = tkinter.Entry(loginUI, show="•")
  76. username_error = tkinter.Label(loginUI, text="[ERROR] INVALID USERNAME", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
  77. password_error = tkinter.Label(loginUI, text="[ERROR] INVALID PASSWORD", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
  78. blank_label_two = tkinter.Label(loginUI, text="", bg="#a1dbcd")
  79. loginUI_button = tkinter.Button(loginUI, text="LOGIN", bg="#d8dbfd", command=getDetails, width="5", font="Arial 11 bold")
  80. # Packs all the labels and entries.
  81. # Will be shown in the loginUI window.
  82. blank_label.pack()
  83. username_label.pack()
  84. username_entry.pack()
  85. password_label.pack()
  86. password_entry.pack()
  87. blank_label_two.pack()
  88. loginUI_button.pack()
  89. # Runs the loginUI
  90. loginUI.mainloop()
Add Comment
Please, Sign In to add comment