Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use sys.exit() to stop a Tkinter program

Is there a problem with using sys.exit() to stop a Tkinter program?

I know normally people use root.destroy() why is that?

like image 476
Lupus Ossorum Avatar asked Feb 03 '26 21:02

Lupus Ossorum


1 Answers

Of course but it will terminate the entire program, including your app.

According to here: https://www.daniweb.com/programming/software-development/threads/66698/exit-a-tkinter-gui-program. root.destroy is a safe, dependable way to exit your Tkinter app. From the link:

destroy() just terminates the mainloop and deletes all widgets. So it seems to be safer if you call your app from another Tkinter app, or if you have multiple mainloops.

like image 69
Anthony Pham Avatar answered Feb 06 '26 09:02

Anthony Pham