Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Perl/Tk window->protocol question

by mnooning (Sexton)
on Mar 17, 2006 at 17:54 UTC ( #537515=perlquestion: print w/ replies, xml ) Need Help??
mnooning has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am writing an event driven system wherein as one top level window is
closed, another pops up. I provide an Exit button on each window that
has it's own routine for cleaning up and exiting. If the user instead
clicks the upper right window cross hair to close the window, I still
want to go to the said cleaning up routine. The call below does not
work. $top of course is a Toplevel reference.

$top->protocol( 'WM_DELETE_WINDOW', \&my_clean_up_routine( $top, $another_parameter);

The call is fashioned after this example from http://www.lns.cornell.edu/~pvhp/ptk/ptkFAQ.html

$window->protocol('WM_DELETE_WINDOW',\&your_exit_handler);

Perhaps the problem is that no parameters are allowed. I am guessing
that because the code below works in that if using it, the said cross
hairs will not close the window out, which breaks tradition.

$window->protocol( 'WM_DELETE_WINDOW', \&Tk::NoOp);

Any ideas?

Comment on Perl/Tk window->protocol question
Select or Download Code
Re: Perl/Tk window->protocol question
by jdporter (Canon) on Mar 17, 2006 at 18:06 UTC
    Perhaps the problem is that no parameters are allowed.

    You've hit the nail on the head. \& takes a reference to the subroutine's implementation, whereas parameters are data that are passed at runtime. Probably the easiest way to achieve what you want here is to wrap your function call in another sub which doesn't require any arguments. This, in turn, can simply call your function, with arguments. Like so:

    $top->protocol( 'WM_DELETE_WINDOW', sub { my_clean_up_routine( $top, $another_parameter ); } );

    (Pay close attention to the braces and parens in that example.)

    We're building the house of the future together.
Re: Perl/Tk window->protocol question
by zentara (Archbishop) on Mar 17, 2006 at 18:44 UTC
    I think you may be looking for the square bracket form of callback
    -command => sub { numpress( $i ) } # equals -command => [ \&numpress, $i ]
    so try
    $top->protocol( DELETE_WINDOW', [\&my_clean_up_routine, $top, $another_parameter] ); [download]

    I'm not really a human, but I play one on earth. flash japh
      It worked. Outstanding!
      Thanks for the quick response, too.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://537515]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-12-25 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (162 votes), past polls