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

Wise Ones!,
I am having a little trouble with perl/tk. I have only just started using it and I am finding it difficult to process some text entry through clicking a button.
I basically have a .pm file with a sub called 'collect', this is referenced in the code below. I need to basically pass whatever is entered in the IP text box to collect, so I thought collect($ipadde) would do the trick...apparently not!
Is there anyone who can give me a hand plz?

use Tk; use Tk::Label; use Tk::Photo; use Tk::Text; use Tk::Notebook; # module that is referenced use saracen_collect; my $mw = MainWindow->new; $mw->title("Data Collection - Saracen"); $mw->MainWindow->Frame(-relief=>'groove'); $mw->minsize(600,300); my $image = $mw->Photo(-file => "saraLogo2.gif"); $mw->Label(-image => 'image1')->pack(-side=> "left", -anchor => 'n'); my $tittle = $mw -> Label(-font => '16', -text => "Specify Host:")->pa +ck(-side => 'top', -anchor => 'w'); my $inp = $mw -> NoteBook(-ipady => '4', -borderwidth => 2, -relief => + 'flat')->pack(-side => 'left', -anchor => 'nw', -side => 'left'); my $tab1 = $inp->add( "Sheet 1", -label=>" IP "); my $f1 = $tab1 -> Frame(-relief => 'flat')->pack(-side => 'top', -anch +or => 'nw'); my $ipaddl = $f1 -> Label(-text => "IP ADDRESS:\t\t\t")->pack(-side => + 'left', -anchor => 'nw'); my $ipadde = $f1 -> Entry(-borderwidth => '5',-background => 'white')- +>pack(-side => 'right', -anchor => 'nw'); my $f2 = $tab1 -> Frame(-relief => 'flat')->pack(-side => 'bottom', -a +nchor => 'sw'); my $confpwdl = $f2 -> Label(-text => "CONFIRM PASSWORD:\t\t")->pack(-s +ide => 'left', -anchor => 'nw'); my $confpwde = $f2 -> Entry(-borderwidth => '5',-background => 'white' +)->pack(-side => 'right', -anchor => 'nw'); my $f3 = $tab1 -> Frame(-relief => 'flat')->pack(-side => 'bottom', -a +nchor => 'sw'); my $pwdl = $f3 -> Label(-text => "PASSWORD:\t\t\t")->pack(-side => 'le +ft', -anchor => 'nw'); my $pwde = $f3 -> Entry(-borderwidth => '5',-background => 'white')->p +ack(-side => 'right', -anchor => 'nw'); my $f4 = $tab1 -> Frame(-relief => 'flat')->pack(-side => 'bottom', -a +nchor => 'sw'); my $userl = $f4 -> Label(-text => "USER NAME:\t\t\t")->pack(-side => ' +left', -anchor => 'nw'); my $usere = $f4 -> Entry(-borderwidth => '5',-background => 'white')-> +pack(-side => 'right', -anchor => 'nw'); my $bf = $mw-> Frame(-pady => '5')->pack(-side => 'bottom', -anchor=>' +se'); my $cancel = $bf -> Button(-relief=> 'raised', -borderwidth => '2', -t +ext => "Cancel", -command => sub {exit;})->pack(-side => 'right',-pad +x => '20'); # It is here I am trying to make the button process the sub. my $next = $bf -> Button(-relief=> 'raised', -borderwidth => '2', -tex +t => "Finish", -command => sub {collect(\$ipadde); exit;})->pack(-sid +e => 'right'); MainLoop;

Cheers, Steve

Replies are listed 'Best First'.
Re: Perl/Tk processing entered text with button
by mawe (Hermit) on Feb 23, 2005 at 15:27 UTC
    Hi!

    To get the text from an Entry, use get(). So this should work:

    ... sub {collect($ipadde->get()); ...

    Regards, mawe

      as an alternative, you can bind a variable to the entry widget, e.g.
      use vars qw($IpAddress); my $entry = $parent->Entry(-textvariable => \$IpAddress) ->pack(-side => 'left'); $parent->Button(-text => 'Go', -command => \&DoIt) ->pack(-side => 'left'); sub DoIt { print "Entry contains: $IpAddress\n"; } # DoIt

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

      Thats wicked mate, cheers!