i was coding an application and I wanted to close a window and open another one via button. however:
from tkinter import *
x1 = Tk()
x2 = Tk()
def xd():
x1.destroy()
x2.mainloop()
boton = Button(x1, text="XD", command=xd)
boton.pack()
x1.mainloop()
This opens 2 windows, x1 and x2. I know already that if I use x2 = Tk()
inside the function xd()
, it will work how I wanted. But my question does remain the same. x2 = Tk()
is supposed to only create a window name variable, and mainloop
is supposed to create it, visually. So, why does this happen?
CodePudding user response:
A single call to mainloop
will make both windows visible. That is simply how tkinter is designed to work. Since you create two windows, you'll see two windows.