Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Tk question

by monktim (Friar)
on Nov 13, 2003 at 22:42 UTC ( #306956=perlquestion: print w/replies, xml ) Need Help??

monktim has asked for the wisdom of the Perl Monks concerning the following question:

When an event occurrs, I'm poping up a window that has a button. When I click the button I'd like to kill the window and continue processing.

How do I kill the window without killing the program? See sub ok below.

Thanks.

use strict; use warnings; use Tk; my $notified = 0; notify(); continue_processing(); exit 0; sub notify { my $win = new MainWindow; $win->Label(-text => 'Window!')->pack; $win->Button(-text => 'OK', -command => sub{ok()})->pack; Tk::MainLoop(); } sub ok { $notified = 1; Tk::exit(0); } sub continue_processing() { print "Here I am $notified\n"; }

Replies are listed 'Best First'.
Re: Tk question
by batkins (Chaplain) on Nov 13, 2003 at 22:49 UTC
    You need to call destroy on the target widget. When you create the button, do something like this:
    $win->Button(-text => 'OK', -command => [\&ok, $win])->pack;
    This will call ok($win) whenever the OK button is triggered (In general, \&ok is clearer than sub { ok() }). ok() then becomes:
    sub ok { my $win = shift; $win->destroy; $notified = 1; }
    Are you sure it was a book? Are you sure it wasn't.....nothing?
      I think the point being sought by the OP was to leave the "Tk::exit" out of this process -- apart from that, you've shown the way quite nicely.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://306956]
Approved by menolly
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-08-09 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?