0

I am making a project for school. This sign up system is working as expected, but the problem is that once an email/password is entered < 3 characters once, even entering a correct length of value causes it to throw the error.

I think it is because the method is not getting the information from my entry forms twice, and is recognizing the first get of data. I have tried to place this is a while loop with well set conditions, it still acts funky.

All I am asking for is that someone introduce me to a simple way for this message box to be thrown once, so they can enter in new information (just as my email already exists statement works).

Code:

def go(self):
    run = True
    email = self.email_entry.get()
    password = self.password_entry.get()

    if len(email) or len(password) < 3:
        tkinter.messagebox.showinfo("Error", "Please enter a valid email/password -- (minimum three characters")
        run = False

    if run:
        if email not in self.customers:
            self.customers[email] = password

            with open("shopping_list.dat", "wb") as data_file:
                pickle.dump(self.customers, data_file)

            self.sign_up.destroy()
            shopping_list = ShoppingList()
        else:
            tkinter.messagebox.showinfo("Error", "The email entered already exists...try again.")
martineau
  • 119,623
  • 25
  • 170
  • 301
Vcubbz
  • 69
  • 7

1 Answers1

0

Hey I sadly don't have enough time to include actual code but here is what I recommend:

When a username or password is under the minimum character limit, set some sort of variable to True. Then make an if statement where if that variable is True, do not allow login, clear Tkinter GUI, and then set the variable to None (like this):

if PasswordMinLengthVar == True:
   Don't allow access
   Clear GUI
   PasswordMinLengthVar == None

Then the login should go back to the login screen and the user can try again.

Ethan J
  • 140
  • 1
  • 9
  • That's great! What did you do to fix it? – Ethan J Nov 30 '20 at 17:59
  • It's very interesting what happened. I changed the *if len(email) or len(password) < 3:* statement to *if len(email) < 3 or len(password) < 3:* and it started to work. Very interesting. I also wrapped the entire dict and pickling statement in an else block to that if statement. – Vcubbz Nov 30 '20 at 18:07
  • Now I am feeling really dumb that I didn't see that. The reason it didn't work is because the interpreter thought you were only trying to apply that to the len(password) and not both. It just thought that len(email) was a blank conditional probably why it gave you an error. My solution was less efficient but still worked because I specified that a variable change would still happen even if only one value was under 3 characters. – Ethan J Nov 30 '20 at 18:13
  • Your solution is still very helpful, I feel even less attentive that I missed that. Thank you for explaining the *why* to this though, len() understood further. – Vcubbz Nov 30 '20 at 18:15