Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. try:
  2. import tkinter as tk
  3. except ImportError:
  4. import Tkinter as tk
  5. # from http://effbot.org/tkinterbook/entry.htm
  6. failure_max = 3
  7. def make_entry(parent, caption, width=None, **options):
  8. tk.Label(parent, text=caption).pack(side=tk.TOP)
  9. entry = tk.Entry(parent, **options)
  10. if width:
  11. entry.config(width=width)
  12. entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
  13. return entry
  14. def enter(event):
  15. check_password()
  16. def check_password(failures=[]):
  17. datafile = open('loginprofile.passwords')
  18. for line in datafile:
  19.  
  20. if (user,'=',password in line):
  21. root.destroy()
  22. print('Logged in')
  23. return
  24. failures.append(1)
  25. if sum(failures) >= failure_max:
  26. root.destroy()
  27. raise SystemExit('Unauthorized login attempt')
  28. else:
  29. root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
  30. root = tk.Tk()
  31. root.wm_iconbitmap("Login icon.ico")
  32. root.geometry('300x160')
  33. root.title('Enter your information')
  34. #frame for window margin
  35. parent = tk.Frame(root, padx=10, pady=10)
  36. parent.pack(fill=tk.BOTH, expand=True)
  37. #entrys with not shown text
  38. user = make_entry(parent, "User name:", 16, show='~')
  39. password = make_entry(parent, "Password:", 16, show="*")
  40. #button to attempt to login
  41. b = tk.Button(parent, borderwidth=4, text="Login", width=10, pady=8, command=check_password)
  42. b.pack(side=tk.BOTTOM)
  43. password.bind('<Return>', enter)
  44. user.focus_set()
  45. parent.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement