mercredi 6 novembre 2019

Problem with a function checking "if" statements

I'm trying to design a simple password system. It works with a function checking 3 if statements. The problem is that even when the password is correct, it does not run the first if statement. It seems like the variable "entry" is never equal to the variable "password", but I don't know why.

##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,"Wrong password\nYou used ")
        text.insert(INSERT,number_of_guesses)
        text.insert(INSERT,"/5 attempts")
        text.insert(INSERT,"\nAccess denied\n")
        text.pack()

Aucun commentaire:

Enregistrer un commentaire