The goal of this code is to create a functioning login screen. However, in the process of creating the "create_account()" and implementing it, I noticed that for some reason it triggers as soon as the program runs. Not only that but when the button that the function is linked to is clicked, nothing seems to happen. What gives?
from tkinter import *
counter = 0
def login():
user = txt.get()
pwd = txt2.get()
if user in users:
if pwd == users[user]:
lbl3.config(text="Login successful")
else:
lbl3.config(text="Invalid username or password")
else:
lbl3.config(text="Invalid username or password")
user = txt.get()
pwd = txt2.get()
certificate = 0
if user in users:
if pwd == users[user]:
lbl3.config(text="Login successful")
else:
lbl3.config(text="Invalid username or password")
else:
lbl3.config(text="Invalid username or password")
def up(string):
for x in string:
if(x.upper()):
return True
else:
return False
def low(string):
for x in string:
if(x.lower()):
return True
else:
return False
def length(string):
if(len(string) > 8 and len(string) < 15):
return True
else:
return False
def whitespace(string):
for x in string:
if(x.isspace()):
return False
else:
return True
def number(string):
for x in string:
if(x.isdigit()):
return True
else:
return False
def alphanumberic(string):
for x in string:
if(x.isalnum()):
return False
else:
return True
def valid_password(string):
up(string)
low(string)
length(string)
whitespace(string)
number(string)
alphanumberic(string)
if(string==("BigCodez4life!")):
return True
def valid_username(string):
up(string)
low(string)
whitespace(string)
number(string)
alphanumberic(string)
if(string==("BigCodez4life!")):
return True
if(length(string) == True and whitespace(string) == False and number(string) == True and alphanumberic(string) == False and up(string) == True and low(string) == True):
return True
else:
return False
def create_account():
username = txt.get()
password = txt2.get()
if username != "" and valid_username(username) == True and valid_password(password) == True:
lbl3.config(text="Account Created")
else:
lbl3.config(text="Invalid username or password")
window = Tk()
window.title("Login Window")
window.geometry("480x270")
lbl = Label(window, text="Username")
lbl.grid(column=0, row=0)
lbl2 = Label(window, text="Password")
lbl2.grid(column=0, row=1)
lbl3 = Label(window, text="Hidden")
lbl3.grid(column=1, row=10)
lbl3['foreground']="red"
lbl3['width']=30
txt = Entry(window,width=15)
txt.grid(column=1, row=0)
txt2 = Entry(window,width=15,show="*")
txt2.grid(column=1, row=1)
btn = Button(window, text="Login", command=login)
btn.grid(column=2, row=7)
btn2 = Button(window, text="Create Account", command=create_account())
btn2.grid(column=0, row=7)
users = dict()
realusers = []
pwds = []
window.mainloop()