in reply to Re: Functions and Tk
in thread Functions and Tk

I changed my code to match yours. There is still something wrong. I am getting the error.
Tk::Error AUTOLOAD 'Tk::Toplevel::destory' at line 97 Carp::croak at C:/usr/lib/Carp.pm line 191 Tk::Widget::__ANON__ at C:/usr/lib/Tk/Widget.pm line 338 main::Exit_Win at line 97 main::__ANON at line 82 [\&main::__ANON__ at line 82 Tk callback for .toplevel.frame2.button1 Tk::__ANON__ at C:/usr/lib/Tk.pm line 228 Tk::Button::butUp at C:/usr/lib/Tk/Button.pm line 111 [command bound to event]
$win->Button(...-command=> sub {$win->destory} )... Works great, but I would like to have the sub work.

Replies are listed 'Best First'.
Re: Re: Re: Functions and Tk
by bobn (Chaplain) on Aug 24, 2003 at 02:59 UTC

    It isn't really working. Tk::Error AUTOLOAD 'Tk::Toplevel::destory' at line 97 happend because you said ->destory when you meant ->destroy - and your window fgoes away because your program died.

    To make the subroutine work, I think the part you're missing is this:

    doit('here is my input', 'some more'); sub doit { my ( $in1, $in2 ) = @_; print "$in1\n"; print "$in2\n"; }

    subs all receive their parameters in @_ - then you transfer them in to local variables for readability, isolation, etc.

    In the orginal form of my example the line my $thiswin = $_[0]; in the close_win sub did this, just getting the first (and only) elment of @_;

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.

      That fixed it. thanks a lot. You have just helped me figure out something that has been driving me nuts for almost a week.

      Thanks again. James
Re: Re: Re: Functions and Tk
by converter (Priest) on Aug 24, 2003 at 03:08 UTC

    The answer is right in front of you: you misspelled destroy.

    converter

      Thanks for your help.
      Passing variables to subs has been something I have working on for awhile. perldoc perlsub, doesnt' seem to say it in such a clear way.

      Thanks again. James