[Python] Trying to get my GUI windows automatically exit when I open the next window

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    How can I manage to automatic cancel this 1st window when I click the next window button?

    sample code:

    from tkinter import *
    from tkinter import messagebox

    root = Tk()
    root.title("GUI practice")

    def open():
    top = Toplevel() # new window
    top.title("Kokomi")
    labels = Label(top, text="This one automatically close when i click the next window").pack()
    button2 = Button(top,text="Close window", command=top.destroy).pack()
    button3 = Button(top,text="Next window", command=open2).pack()

    def open2():
    top = Toplevel() # new window
    top.title("Guide")
    labels = Label(top, text="end").pack()
    button2 = Button(top, text="Close window", command=top.destroy).pack() # destroy to quit things

    button = Button(root, text="Open(No need to close this)", command=open).pack()


    root.mainloop()


    [Click open][1]
    [Click Next window and after that this windows should disappear and continue to the 3rd picture][2]
    [The 2nd picture goes disappear when i click the next window][3]

    [1]: https://i.sstatic.net/plS1T.png
    [2]: https://i.sstatic.net/EFW76.png
    [3]: https://i.sstatic.net/xSZCp.png

    Continue reading...

Compartilhe esta Página