[Python] How to close tkinter window without a button and not closing Python completely?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am aware that there are commands such as .destroy() , .exit() etc. However, when taking these out of the 'command' from the button parameter of what action to take when pressed, they don't work.

    My scenario is when a user logins successfully, the Tkinter window including its widgets should close whilst short after a GUI in pygame opens. I just don't want the Tkinter window to be there once I don't need it ever again whilst also not exiting Python. I don't want a button as I want the process to be automatic.

    The thing that baffles me is why when taking out this command to be on its own, it does not work:

    Button(root, text="Quit", command=root.destroy).pack() #works
    root.destroy() #don't works

    Continue reading...

Compartilhe esta Página