Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Creating the getDetails function.
- # Gets the username and opens the file of the username.
- # If the file doesn't exit / username is invalid,
- # An error message is shown.
- def getDetails():
- # Makes the variable "username" global.
- # Can be accessed by other functions later.
- global username
- username = username_entry.get()
- try:
- usernameFile = open(username + ".txt", 'r+')
- usernameFileLine = usernameFile.readlines()
- # Gets the password the user input.
- password = password_entry.get()
- username_error.pack_forget()
- # Checks if the password is correct.
- # If not, an error message is shown.
- if password == usernameFileLine[0]:
- # Function to open the optionUI.
- optionMenu()
- # Closes the loginUI.
- loginUI.destroy()
- else:
- password_error.pack()
- # Checks if the username is invalid.
- except FileNotFoundError:
- # Packs the error message for invalid username.
- username_error.pack()
- # Creates the main loginUI.
- # Don't need a function for this.
- loginUI = tkinter.Tk()
- loginUI.title("loginUI")
- loginUI.geometry("400x200")
- loginUI.configure(background="#a1dbcd")
- # Creating all the labels and entries for the loginUI.
- blank_label = tkinter.Label(loginUI, text="", bg="#a1dbcd")
- username_label = tkinter.Label(loginUI, text="USERNAME", font="Arial 8 bold", bg="#a1dbcd")
- username_entry = tkinter.Entry(loginUI)
- password_label = tkinter.Label(loginUI, text="PASSWORD", font="Arial 8 bold", bg="#a1dbcd")
- password_entry = tkinter.Entry(loginUI, show="•")
- username_error = tkinter.Label(loginUI, text="[ERROR] INVALID USERNAME", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
- password_error = tkinter.Label(loginUI, text="[ERROR] INVALID PASSWORD", font="Arial 7 bold", fg="#ff0000", bg="#a1dbcd")
- blank_label_two = tkinter.Label(loginUI, text="", bg="#a1dbcd")
- loginUI_button = tkinter.Button(loginUI, text="LOGIN", bg="#d8dbfd", command=getDetails, width="5", font="Arial 11 bold")
- # Packs all the labels and entries.
- # Will be shown in the loginUI window.
- blank_label.pack()
- username_label.pack()
- username_entry.pack()
- password_label.pack()
- password_entry.pack()
- blank_label_two.pack()
- loginUI_button.pack()
- # Runs the loginUI
- loginUI.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement