Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
12-01-2016, 12:24 PM #1
- Join Date
- Nov 2016
- South Africa, Cape Town
- Thanked 1 Time in 1 Post
Tracking Window Close Event Tkinter
This may not be of any help to 90% of the people who read it but it's something I've always searched for and came up with nothing but finally I have the code.
This is to track the window close event ( when the user clicks the red X on the window or in general exits the window ) and also a good method to handle search boxes that are pop-ups.
import Tkinter root = Tk() def onClose(): print "The Window Was Closed" root.protocol("WM_DELETE_WINDOW", onClose) #This is the piece which tracks the window exit status root.mainloop()
This is how I did it - going with the code above and assuming that our main windows Tk() instance's name is mainRoot:
import Tkinter root = Tk() mainRoot.wm_attributes("-disabled", 1") #While our new window is open set the background ( main ) window state to disabled def onClose(): mainRoot.wm_attributes("-disabled", 0) #enabled the window again on exit root.protocol("WM_DELETE_WINDOW", onClose) #This is the piece which tracks the window exit status root.mainloop()