0

So, I am making a login system in python with tkinter and I want it to move to another page after the email and password have been validated. The only way I have found to do this is by using a button click command. I only want it to move on to the next page after the email and password have been validated. Thanks in advance.

    from tkinter import *


    class login:

        def __init__(self, master, *args, **kwargs):

            self.emailGranted = False
            self.passwordGranted = False

            self.attempts = 8

            self.label_email = Label(text="email:", font=('Serif', 13))
            self.label_email.grid(row=0, column=0, sticky=E)

            self.label_password = Label(text="password:", font=('Serif', 13))
            self.label_password.grid(row=1, column=0, sticky=E)

            self.entry_email = Entry(width=30)
            self.entry_email.grid(row=0, column=1, padx=(3, 10))

            self.entry_password = Entry(width=30, show="•")
            self.entry_password.grid(row=1, column=1, padx=(3, 10))

            self.login = Button(text="Login", command=self.validate)
            self.login.grid(row=2, column=1, sticky=E, padx=(0, 10), pady=(2, 2))

            self.label_granted = Label(text="")
            self.label_granted.grid(row=3, columnspan=3, sticky=N+E+S+W)

        def validate(self):

            self.email = self.entry_email.get()
            self.password = self.entry_password.get()

            if self.email == "email":
                self.emailGranted = True

            else:
                self.emailGranted = False
                self.label_granted.config(text="wrong email")
                self.attempts -= 1
                self.entry_email.delete(0, END)
                if self.attempts == 0:
                    root.destroy()

            if self.password == "password":
                self.passwordGranted = True

            else:
                self.passwordGranted = False
                self.label_granted.config(text="wrong password")
                self.attempts -= 1
                self.entry_password.delete(0, END)
                if self.attempts == 0:
                    root.destroy()

            if self.emailGranted is False and self.passwordGranted is False:
                self.label_granted.config(text="wrong email and password")

            if self.emailGranted is True and self.passwordGranted is True:
                self.label_granted.config(text="access granted")
                // I want it to move on to PageOne here but I'm not sure how

    class PageOne:

        def __init__(self, master, *args, **kwargs):

            Button(text="it works").grid(row=0, column=0)

    if __name__ == "__main__":

        root = Tk()
        root.resizable(False, False)
        root.title("login")
        login(root)
        root.mainloop()
Zzyborg
  • 15
  • 2
  • See [the general answer](https://stackoverflow.com/q/48723444/7032856). – Nae Feb 28 '18 at 19:44
  • _When_ do you want it to get validated? – Nae Feb 28 '18 at 20:00
  • Every time the user clicks the button the program checks to see if the inputs match the set email and password. It's checked every button click. – Zzyborg Feb 28 '18 at 20:09
  • I asked my question _despite_ understanding that. If that's what you _want_, don't you already have it? – Nae Feb 28 '18 at 20:14

2 Answers2

0

I haven't used tkinter, but moving to a new page is like an action. And actions are performed when an event occurs. In your case the event is after the email and password passes validation. So you need to add logic to move to the new page after the validation is successful.

BTW why do you want to do this? Why not have the user press a button instead?

Silencer310
  • 862
  • 2
  • 8
  • 25
0

If you want to make it so it will move on as soon as there is a valid email then you want to make there be a function that will get a parameter (the email) and will return a Boolean value (True or False). To do that you need to make it like this:

def function(email):
   return email == <something>

To make it check this over and over when they are typing would be to use root.update() in a loop instead of root.mainloop() this way you can do something like this:

while function(entryWidget.get()):
   #all the configs for text
   root.update()
#let them to the next page

Is this helpful?

Hippolippo
  • 803
  • 1
  • 5
  • 28