OrangoMango

LoginInterface Tutorial

May 7th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #Login Interface tutorial
  2.  
  3. from tkinter import * #import tkinter module
  4. from tkinter import messagebox #import messagebox
  5.  
  6. tk = Tk()
  7. tk.title("Login Interface")
  8.  
  9. def confirm(): #Confirm function of the button
  10.     username = entrys[0].get()
  11.     password = entrys[1].get()
  12.     accept = variable.get()
  13.     if username == "OrangoMango" and password == "bingo" and accept == 1:
  14.         #we check if username and password are correct
  15.         messagebox.showinfo("Login", "Login correct")
  16.     else:
  17.         messagebox.showerror("Login", "Login incorrect")
  18.    
  19. entrys = [] #list of text areas
  20. labelstext = ["Enter username:", "Enter password:"]
  21.  
  22. for x in range(2):
  23.     l = Label(tk, text=labelstext[x]) #Label with the text of the list
  24.     l.grid(column=0, row=x) #We put the label in a grid layout
  25.     e = Entry(tk, show="" if x == 0 else "*") #we show the normal characters if we need to input the username, the password is shown with *
  26.     e.grid(column=1, row=x)
  27.     entrys.append(e) #We add the entry to the list
  28.  
  29. variable = IntVar() #we create a tkinter variable
  30. #If the checkbutton is active variable = 1, else variable = 0
  31. c = Checkbutton(tk, text="Accept therms of privacy", variable=variable, onvalue=1, offvalue=0) #we create a checkbutton
  32. c.grid(column=0, row=2, columnspan=2)
  33. b = Button(tk, text="Confirm", command=confirm) #We create a button
  34. #with the confirm text and the confirm function
  35. b.grid(column=1, row=3, sticky="e")
  36. tk.mainloop()
Add Comment
Please, Sign In to add comment