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

I am trying to write a super simple widget that binds a system call to a widget button..here is the widget

use Tk; $MW = MainWindow->new; $angel = $MW->Button( -text => 'Launch Scripts', -command => sub {print STDOUT "Launch Scripts\n"; exit;} ); $angel->pack; MainLoop;

I want to bind the system call to the action of the button push

system ("./scriptname");

Replies are listed 'Best First'.
Re: Tk binding...
by legato (Monk) on Jan 07, 2005 at 18:59 UTC

    That is what the -command parameter of Button is for. So, construct your button thus:

    $angel = $MW->Button( -text => 'Launch Scripts', -command => sub { print STDERR "Launching..."; system("./scriptname"); }, ); ##not sure why you're using exit, so I left it out.
    That will run ./scriptname on every button press.

    Anima Legato
    .oO all things connect through the motion of the mind

Re: Tk binding...
by Anonymous Monk on Jan 07, 2005 at 19:39 UTC
    If I run that I get this error...
    C:\>angel.pl Unquoted string "angel" may clash with future reserved word at C:\ange +l.pl line 4. Name "main::angel" used only once: possible typo at C:\angel.pl line 5 +. Can't locate object method "new" via package "angel" (perhaps you forg +ot to load "angel"?) at C:\angel.pl line 4.

      Maybe you forgot to put a $ in front of angel in line 4?

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      That's very odd; I don't. What version of Perl are you running?
        C:\>perl -v This is perl, v5.8.4 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail)