我正在尝试设计一个简单的密码系统。它与检查3 if语句的函数一起使用。问题是,即使密码正确,它也不会运行第一个if语句。
似乎变量entry
永远不会等于变量password
,但我不知道为什么。
##user input space
entry=Entry(top,bd=5)
entry.pack(side=LEFT)
##actual password to be set
password="abc"
number_of_guesses=0
##function to check user input
def r():
global entry,password,number_of_guesses
number_of_guesses+=1
if entry==password and number_of_guesses<5:
root=Tk()
text=Text(root)
text.insert(INSERT,"You shall pass\nAttempts used:")
text.insert(INSERT,number_of_guesses)
text.pack()
elif number_of_guesses<5 and number_of_guesses>0:
root=Tk()
text=Text(root)
text.insert(INSERT,"Wrong password\nYou used ")
text.insert(INSERT,number_of_guesses)
text.insert(INSERT,"/5 attempts")
text.pack()
elif number_of_guesses>=5:
root=Tk()
text=Text(root)
text.insert(INSERT,"/5 attempts")
text.insert(INSERT,"\naccess denied\n")
text.pack()