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

i am trying to write a perl/tk code to popup a window press a buuton in the main window so that a new popupchild will come My Code
use Tk; use strict; my $mw = MainWindow->new; $mw->geometry("500x200"); $mw->title("All-In-One Test"); my $but=$mw->Button(-text=>"press",-command=>"\&newwindow")->pack(); sub newwindow(){ my $popup=$mw->Toplevel()->pack(); } MainLoop;
but i getting the following error while pressing the button even though i have Tk-804.028_501 installed along with my perl
Tk::Error: Undefined subroutine &main::&newwindow called at /tools/openbin/perl/5.10.0/sparc-sun-solaris8/lib/site_perl/5.10.0/sun4-solaris-thread-multi/Tk.pm line 250. Tk callback for .button Tk::__ANON__ at /tools/openbin/perl/5.10.0/sparc-sun-solaris8/lib/site_perl/5.10.0/sun4-solaris-thread-multi/Tk.pm line 250 Tk::Button::butUp at /tools/openbin/perl/5.10.0/sparc-sun-solaris8/lib/site_perl/5.10.0/sun4-solaris-thread-multi/Tk/Button.pm line 175 <ButtonRelease-1> (command bound to event)

Replies are listed 'Best First'.
Re: perl/Tk error
by zentara (Cardinal) on Dec 03, 2008 at 13:29 UTC
    That's easy, remove the double quotes around "\&newwindow". Also you can't pack a toplevel window.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      thanks
Re: perl/Tk error
by hominid (Priest) on Dec 03, 2008 at 13:32 UTC
    Try getting rid of the quotes around the callback, like this
    my $but=$mw->Button(-text=>"press",-command=>\&newwindow)->pack();