Python Forum
[Tkinter] How to close all windows when exit program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] How to close all windows when exit program (/thread-26877.html)



How to close all windows when exit program - scratchmyhead - May-17-2020

I was just wondering if there is a way to close all open windows upon program exit?


RE: How to close all windows when exit program - menator01 - May-17-2020

If they are all toplevel windows of your root window, closing root window should close all


RE: How to close all windows when exit program - scratchmyhead - May-17-2020

But I have a self.root window that is still open when I close the main program.

class App():
    def __init__(self):
        self.root = tk.Tk()
        self.label = Label(text="")
        self.label.pack()
        self.update_clock()
        self.root.mainloop()

    def update_clock(self):
        now = time.strftime("%H:%M:%S")
        #self.label.configure(text=now)

        # Put Arrivals in box===============================================================
        arrivallb.delete(0, END)
        now = dt.datetime.now()
        dte = now.strftime("%m-%d-%Y")

        conn = sqlite3.connect('reservation.db')
        c = conn.cursor()
        c.execute("SELECT * FROM reserve")
        records = c.fetchall()

        for record in records:
            if record[22] != "*":



RE: How to close all windows when exit program - menator01 - May-17-2020

The mai program should be the only root window all else can be toplevel windows (new windows that open up). Just my opinion. When the main root is closed all toplevel windows should close with it.
Some reading links
https://python-tricks.com/toplevel-in-tkinter/
https://www.tutorialspoint.com/python/tk_toplevel.htm
https://riptutorial.com/tkinter/example/22130/difference-between-tk-and-toplevel