Fire Frekox
Fire Frekox

Reputation: 71

Why are there 2 windows opened here? Tkinter

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?

Upvotes: 0

Views: 489

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

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.

Upvotes: 1

Related Questions