-
Notifications
You must be signed in to change notification settings - Fork 0
/
login-botique.py
65 lines (56 loc) · 2 KB
/
login-botique.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
try:
import tkinter as tk
from tkinter import messagebox
print("running in python3")
except ImportError:
print("runnning in python2.7")
import Tkinter as tk
# from http://effbot.org/tkinterbook/entry.htm
from tkinter import *
failure_max = 3
passwords = [('root', 'toor'), ('suman', 'password')]
def make_entry(parent, caption, width=None, **options):
tk.Label(parent, text=caption).pack(side=tk.TOP)
entry = tk.Entry(parent, **options)
if width:
entry.config(width=width)
entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
return entry
def enter(event):
check_password()
def window2_init():
root = Tk()
#win2 = TopLevel()
root.title("main window")
llb1 = Label(root,text="hello this will be main window").pack()
btn1 = Button(root,font("arial", 20, "italic"), padx=16,pady=16, bg="black" ,fg="white",relief="RAISED").pack()
root.mainloop()
def check_password(failures=[]):
""" Collect 1's for every failure and quit program in case of failure_max failures """
print(user.get(), password.get())
if (user.get(), password.get()) in passwords:
root.destroy()
#messagebox.showinfo('Logged in')
window2_init()
return
failures.append(1)
if sum(failures) >= failure_max:
root.destroy()
raise SystemExit('Unauthorized login attempt')
else:
root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
root = tk.Tk()
root.geometry('300x160')
root.title('Enter your information')
#frame for window margin
parent = tk.Frame(root, padx=10, pady=10)
parent.pack(fill=tk.BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16)
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = tk.Button(parent, borderwidth=4, text="Login", width=10, pady=8, command=check_password)
b.pack(side=tk.BOTTOM)
password.bind('<Return>', enter)
user.focus_set()
parent.mainloop()