Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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
[holli]: i saw that thread and figured it`s OPP value too high. i didnt realise its PM code
[LanX]: its the style attribute, I can't show you pm code, can only link to old everything docs of you want
[holli]: i'd like to keep my sanity, tyvm
[holli]: at least what's left off it :)
[LanX]: the+everything+ bible

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-11-20 21:42 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (294 votes). Check out past polls.