Home > Archive > PerlTk > February 2008 > OnDestroy to save contents of text widget
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
OnDestroy to save contents of text widget
|
|
| fossildoc 2008-02-27, 7:07 pm |
| I have a Toplevel containing a text widget. I'd like to prompt the
user to save the contents if he clicks the window's close button.
OnDestroy seems to be way to do this, but I need to pass arguments to
the ondestroy method; the syntax for this is not clear. When I use the
callback system of passing a reference to a list, the first member of
which is a sub ref, I get error messages. Even without arguments, my
text widget seems to be destroyed by the time OnDestroy runs.
Other posts on this topic are ambiguous. Has anyone actually gotten
this to work? If yes, were arguments passed to the ondestroy method?
How?
I'm running build 813 on 'doze.
| |
| Ch Lamprecht 2008-02-27, 7:07 pm |
| fossildoc schrieb:
> I have a Toplevel containing a text widget. I'd like to prompt the
> user to save the contents if he clicks the window's close button.
>
> OnDestroy seems to be way to do this, but I need to pass arguments to
> the ondestroy method; the syntax for this is not clear. When I use the
> callback system of passing a reference to a list, the first member of
> which is a sub ref, I get error messages. Even without arguments, my
> text widget seems to be destroyed by the time OnDestroy runs.
>
> Other posts on this topic are ambiguous. Has anyone actually gotten
> this to work? If yes, were arguments passed to the ondestroy method?
> How?
>
> I'm running build 813 on 'doze.
use strict;
use warnings;
use Tk;
my $mw = tkinit;
my $t = $mw->Text->pack;
$mw->protocol('WM_DELETE_WINDOW',\&ask);
MainLoop;
sub ask{
my $dlg = $mw->Dialog(-text => 'Save changes?',
-buttons => ['yes','no'],
);
my $choice = $dlg->Show;
print "save? $choice !\n";
#etc
if ($choice eq 'no') {$mw->destroy}
}
HTH, Christoph
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
|
|
|
|
|