from tkinter import * w = Tk() def c(): global w print('Window closing') w.destroy() w.protocol('WM_DELETE_WINDOW', c)