Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. # Creating the getDetails function.
  2. # Gets the username and opens the file of the username.
  3. # If the file doesn't exit / username is invalid,
  4. # An error message is shown.
  5. def getDetails():
  6. # Makes the variable "username" global.
  7. # Can be accessed by other functions later.
  8. global username
  9. username = username_entry.get()
  10. try:
  11. usernameFile = open(username + ".txt", 'r+')
  12. usernameFileLine = usernameFile.readlines()
  13. # Gets the password the user input.
  14. password = password_entry.get()
  15. username_error.pack_forget()
  16. # Checks if the password is correct.
  17. # If not, an error message is shown.
  18. if password == usernameFileLine[0]:
  19. # Function to open the optionUI.
  20. optionMenu()
  21. # Closes the loginUI.
  22. loginUI.destroy()
  23. else:
  24. password_error.pack()
  25. # Checks if the username is invalid.
  26. except FileNotFoundError:
  27. # Packs the error message for invalid username.
  28. username_error.pack()
  29.  
  30.  
  31. # Creates the main loginUI.
  32. # Don't need a function for this.
  33. loginUI = tkinter.Tk()
  34. loginUI.title("loginUI")
  35. loginUI.geometry("400x200")
  36. loginUI.configure(background="#a1dbcd")
  37. # Creating all the labels and entries for the loginUI.
  38. blank_label = tkinter.Label(loginUI, text="", bg="#a1dbcd")
  39. username_label = tkinter.Label(loginUI, text="USERNAME", font="Arial 8 bold", bg="#a1dbcd")
  40. username_entry = tkinter.Entry(loginUI)
  41. password_label = tkinter.Label(loginUI, text="PASSWORD", font="Arial 8 bold", bg="#a1dbcd")
  42. password_entry = tkinter.Entry(loginUI, show="•")
  43. username_error = tkinter.Label(loginUI, text="[ERROR] INVALID USERNAME", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
  44. password_error = tkinter.Label(loginUI, text="[ERROR] INVALID PASSWORD", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
  45. blank_label_two = tkinter.Label(loginUI, text="", bg="#a1dbcd")
  46. loginUI_button = tkinter.Button(loginUI, text="LOGIN", bg="#d8dbfd", command=getDetails, width="5", font="Arial 11 bold")
  47. # Packs all the labels and entries.
  48. # Will be shown in the loginUI window.
  49. blank_label.pack()
  50. username_label.pack()
  51. username_entry.pack()
  52. password_label.pack()
  53. password_entry.pack()
  54. blank_label_two.pack()
  55. loginUI_button.pack()
  56. # Runs the loginUI
  57. loginUI.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement