0

So, I have a script that needs to "clean up" when it is exited: it needs to clear a special logging file and other small things that affect the next startup of the script. The script has a GUI written in Tkinter, if that is relevant at all.

Is there any way to run some "cleanup code" regardless of how the script is exited?

Thanks in advance.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by SoulMazer
0

Something like this ...

from Tkinter import *

def exit():
    # do cleanup code here
    pass

root = Tk()
# respond to window title bar  x click
root.protocol("WM_DELETE_WINDOW", exit)

root.mainloop()
0

You should also read the documentation of the standard lib module atexit which gives example of how you can register functions to be executed at program termination.

Edited by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.