Python Forum
[Tkinter] How to close all windows when exit program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to close all windows when exit program
#1
I was just wondering if there is a way to close all open windows upon program exit?
Reply
#2
If they are all toplevel windows of your root window, closing root window should close all
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
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] != "*":
Reply
#4
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,233 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  [Tkinter] Program with Multiple Windows - how to use Class: Riddle 1 2,933 Apr-09-2020, 08:30 PM
Last Post: Riddle
  How to close one of the windows in Tkinter scratchmyhead 3 4,759 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Program strange behavior ( windows doesn't close) adam2020 2 2,161 May-12-2019, 09:19 PM
Last Post: adam2020
  [PyQt] Close program using Push Button with the help of input from a Message Box bhargavbn 2 6,610 Oct-30-2018, 05:09 AM
Last Post: bhargavbn
  [Tkinter] How to exit when multiple root windows. weatherman 4 5,459 May-10-2018, 11:52 PM
Last Post: Larz60+
  OnExit closes windows, but dosen't exit application Larz60+ 3 4,746 Sep-23-2017, 06:12 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020