'how to display entry widget on new window in tkinter?

from tkinter import *
from tkinter import messagebox

w = Tk()

w.geometry('200x250')

def buttons():
    r1 = Tk()
    r1.geometry('200x250')
    r1.mainloop()





t= Label(text = "MIB",font =("Arial", 49))
t.pack(side = TOP)

e = Label(text = "Email")
e1 =Entry()

e.pack()
e1.pack()

p = Label(text = "Password")
p.pack()

p1 = Entry()
p1.pack()

b= Button(text = "SIGN UP", command = buttons)
b.pack()
w.mainloop()

How I can display the entry widget after clicking submit button in the new window in tkinter python? I tried defining under button function but it is showing me the window but not the widgets. The widgets are only displayed on the first window after clicking submit button.



Solution 1:[1]

TK() is the root window, so it needs to be called only once. After that, to open another window, you need to use tkinter.Toplevel(). Below is the code I put labelexample in a new window.

from tkinter import *
from tkinter import messagebox

w = Tk()

w.geometry('200x250')

def buttons():
    r1 = Toplevel(w)
    r1.geometry('200x250')
    labelexample = Label(r1, text = 'GOOD')
    labelexample.pack()

t= Label(text = "MIB",font =("Arial", 49))
t.pack(side = TOP)

e = Label(text = "Email")
e1 =Entry()

e.pack()
e1.pack()

p = Label(text = "Password")
p.pack()

p1 = Entry()
p1.pack()

b= Button(text = "SIGN UP", command = buttons)
b.pack()
w.mainloop()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Desty