1

I am a beginner and I am making a login system (just for practicing). I'm using tkinter to develop a simple UI. The thing is that when I call a second root (sign_in root) with a button from another root (main_screen), and I try to get some values typed in entry with StringVars assigned to them, they return just an empty string ""

    def main_screen():

        root=Tk()
        user=StringVar()
        pas=StringVar()

        btn2=Button(root,text='Sign-In',command=sign_in_screen)
        btn2.place(x=125,y=160)

        root.mainloop()

   def sign_in_screen():
        root1=Tk()
        newuser=StringVar()
        newpas=StringVar() 

        ent3=Entry(root1,width=28,textvariable=newuser) 
        ent3.place(x=100,y=50)

        ent4=Entry(root1,width=28,textvariable=newpas,show="*")
        ent4.place(x=100,y=100)

        btn3=Button(root1,text='Sign-In',command=lambda:register(newuser.get(), newpas.get()))
        btn3.place(x=50,y=160)

        root1.mainloop()

    main_screen()

1 Answer 1

1

Having multiple instances of Tk become hideously complicated because each one creates a separate tcl interpreter. This causes weird effects like what you see here. It's you almost always want to use the Toplevel widget.

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

1 Comment

Thank you so much, I was struggling with this "bug" the whole afternoon. Your answer saves me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.