Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk - Tying events to closing a window

Status
Not open for further replies.

sloppyhack

Technical User
Apr 17, 2001
111
US
I have a TK gui used for updating a database. I'm having a problem with the users closing the window via the button in the top right hand corner and leaving the database connection open. I would like to tie the same "cleanup" process associated with the "CLOSE" button I created to the standard Windows close-window (X) button.

Anyone know how to tie events to that button?

Thanks

Cheers,

Sloppyhack
 
From Mastering Perl/Tk
The protocol method controls the following window properties: WM_DELETE_WINDOW, WM_SAVE_YOURSELF, and WM_TAKE_FOCUS. The callback (if any) associated with each property will be invoked when the window manager recognizes the event associated with the property:

$toplevel->protocol ( [ property_name] [, callback ] );

The WM_DELETE_WINDOW property callback is invoked when the window has been deleted by the window manager. By default, there is a callback assigned by Perl/Tk that destroys the window. If you assign a new callback, your callback will be invoked instead of the default callback. If you need to save data associated with that window, do so in the callback, then invoke $toplevel->destroy() to mimic the correct behavior afterward.

Never used this method so I can't give a specific example, but maybe this link will help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top