1
class StartUp():
    def __init__(self):
        pass

    def verify(self):
        username = ("s")
        password = ("s")
        
        usernameEntry = usernameVar.get()
        passwordEntry = passVar.get()

        start = StartUp()

        if usernameEntry == username and passwordEntry == password:
            start.login() 
        else: 
            #messagebox.showerror("Error","Wrong Credentials")

            
    def login(self):
        #Create a window
        global usernameVar, passVar
        
        verify = StartUp()
        
        window = Tk()
        window.title("Login")
            
        userPassLabel = Label(window, font="Helvetica 18 bold", text="Royal Mail")
        userPassLabel.grid(row=0, column=0, sticky=W)

        usernameVar = StringVar()
        usernameLabel = Label(window, font="Arial", text="Username:")
        usernameLabel.grid(row=1, column=0, sticky=W)
        usernameEntry= Entry(window, width=30, bg="light blue",textvariable = usernameVar, )
        usernameEntry.grid(row=1, column=1, sticky=W)
            
        passVar = StringVar()
        passLabel = Label(window, font="Arial", text="Password:")
        passLabel.grid(row=2, column=0, sticky=W)
        passEntry= Entry(window, width=30, bg="light blue",textvariable = passVar, show ="●")
        passEntry.grid(row=2, column=1, sticky=W)
        
        b1= Button(window, text="Enter", command=verify.verify())
        b1.grid(row=3, column=0, sticky=W)

        window.mainloop()


start = StartUp()
start.login()

The code seems to not work. The message box will just pop up. The enter button then doesn't work. Not sure what is wrong. I'm very new to OOP so not sure whether it's to do with that.

An additional question is how am I able to carry one variable from an input box in one window/class to another window/class? Is global a viable option or is there a better way I can use .get() from an Entry box.

Thanks for the help

0

1 Answer 1

2

When you use (), you are calling the function immediately. And when you use () with a button, it destroys the purpose of having a button itself. So remove the parenthesis, ().

b1 = Button(window, text="Enter", command=verify.verify)

When the function gets called, the value inside the entry are empty and hence else is triggered.

Sign up to request clarification or add additional context in comments.

8 Comments

This fixed it, thanks :)
@CoolCloud: Re-answering duplicate questions is not the best way to boost your rep…
@CoolCloud yeah, you answered so quick I had to wait 5 mins :)
@martineau Most of the time it's easier to just answer the question. I think that that is a flaw with stackoverflow. The only solution that I can think of is a website with the most common tkinter mistakes that I can just bookmark.
@martineau Laziness? I mean we all have our own job apart from answering questions and looking for duplicates too right? I did have all this copied somewhere, but I lost all of it on a system reset too. We could just ignore this question and wait for someone else to mark as duplicate too though. But I don't think ignoring and hoping is the best practice.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.