Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter
- # 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.
- def optionMenu():
- # Checks if the adminUI is open.
- # Makes optionUI global.
- # Can be closed later in another function.
- global optionUI
- optionUI = tkinter.Tk()
- optionUI.title("Main Menu")
- optionUI.geometry("400x200")
- optionUI.configure(background="#FFFF99")
- # Creates a blank line.
- blank = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
- view_Details = tkinter.Button(optionUI, text='VIEW DETAILS', font="Arial 10 bold", command=viewDetails).pack()
- blank2 = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
- changePasswordoptionUI = tkinter.Button(optionUI, text='CHANGE PASSWORD', font="Arial 10 bold", command=changePassword).pack()
- blank3 = tkinter.Label(optionUI, text="", bg="#FFFF99").pack()
- # Opens the admin file.
- admin = open('admins.txt', 'r+')
- adminUIMenuButton = tkinter.Button(optionUI, text='ADMINISTRATOR MENU', font="Arial 10 bold", command=adminMenu)
- contactUIMenuButton = tkinter.Button(optionUI, text='CONTACT ADMINISTRATOR', font="Arial 10 bold", command=contactMenu)
- lines = admin.readlines()
- # Checks if the user is an admin.
- if username in lines:
- # Packs the adminUI button.
- adminUIMenuButton.pack()
- optionUI.mainloop()
- else:
- # Packs the contactUI button.
- contactUIMenuButton.pack()
- optionUI.mainloop()
- 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()
Add Comment
Please, Sign In to add comment