[Newbie] Tkinter Question

Wildman best_lay at yahoo.com
Thu Feb 25 00:13:53 EST 2016


On Tue, 23 Feb 2016 16:19:43 -0600, Wildman wrote:

> <snip for brevity>

Thanks to Christian and Chris.  You both gave me much
to think about and to experiment with.  That adds to
my on-going learning experience.

This is the first thing I tried:

The Exit button has this:  command=self.quit

Then I have this:

def clean_up():
     # delete temp files

root = Tk()
app = Window(root)
root.protocol("DELETE_WINDOW", clean_up)
root.mainloop()

And I also tried:

root.wm_protocol("WM_DELETE_WINDOW", clean_up)

Both worked when the window [X] button was clicked but
neither worked when the Exit button was clicked.
However, when I removed the protocol statement and
replaced with this, it worked for both:

import atexit

atexit.register(clean_up)

Nothing I tried would fire the clean_up routine when
the program was force killed.

In addition I should mention that I can't us the OS
to delete the temp files because a shelled process
creates them.  It may be possible to still do it but
my limited experience does not allow me to pursue it.

Anyway, I am happy with the outcome even though I have
not found a way to detect when the program is force
killed.  It is unlikely that would ever occur as long
as the program does not lock up.  It is up to me to
make sure that doesn't happen. :-)

Thanks again.

-- 
<Wildman> GNU/Linux user #557453
"Philosophy is common sense with big words."
  -James Madison


More information about the Python-list mailing list