Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Tk before destroy event

by fluffyvoidwarrior (Monk)
on Jan 25, 2006 at 11:53 UTC ( #525421=perlquestion: print w/replies, xml ) Need Help??
fluffyvoidwarrior has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, Can anyone tell me how to run code BEFORE a main window is destroyed in Tk. Basically I want to clean up my temp files when the user quits my app. OnDestroy doesn't seem to be the way to do it Thanks all

Replies are listed 'Best First'.
Re: Tk before destroy event
by rinceWind (Monsignor) on Jan 25, 2006 at 12:08 UTC

    Not sure what you mean by OnDestroy. The standard way of doing this is to bind a <Destroy> event on a passive widget (such as a label) on your main window. Don't bind the main window itself, as all subwidgets will inherit the binding; that way leads to much confusion and many bugs.

    If you don't mind the cleanup happening after the main window is destroyed, you can always put the cleanup code after MainLoop, so it won't get called until MainLoop returns.


    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      Yes. Thanks, I've got it now.
Re: Tk before destroy event
by strat (Canon) on Jan 26, 2006 at 09:03 UTC

    Maybe the following piece of code might be interesting for you:

    use Tk (); use Tk::Dialog (); my $mw = MainWindow->new(); $mw->protocol('WM_DELETE_WINDOW', \&ExitApplication); # ------------------------------------------------------------ sub ExitApplication { my $dialog = $mw->Dialog(-text => 'Programm wirklich beenden?', -bitmap => 'question', -title => 'Programm beenden', -default_button => 'Yes', -buttons => [qw/Yes No/], ); my $answer = $dialog->Show(); # and display dialog if (lc($answer) eq 'yes'){ # perhaps save data if necessary... exit; } else { # continue } # else } # ExitApplication

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://525421]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-06-22 03:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.