Python Forum

Full Version: How to close all windows when exit program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was just wondering if there is a way to close all open windows upon program exit?
If they are all toplevel windows of your root window, closing root window should close all
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] != "*":
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/...d-toplevel