There are many, many examples on how to make a multiple entry
dataentry form in Perl Tk but the only one of them that I found to
tell you how to get the
data back from from your entry form was discussed in a 1997 Alois
Steindl post
and it was not a fully working example (and also I was confused by the
variable
$ARG in his example because I thought it might be referring to some
universal
such as STDIN, etc. Don't laugh - that is the sort of thing insecure
beginners get hung up on.
So here is a complete little program that makes an entry form and
fetches the
entered information back from the entry form so you can save it to a
file or whatever.
I have made the labels an array so you could load them from a config
file.
or from the first line of a dataset.
##### Program Modified from 1997 Post by Alois Steindl########
#!/usr/bin/perl/
use Tk;
use strict;
our @labels =("Name","Street Address","City","
State","Zip","Country");
our $item; our %efeld; our $l; our $e;
use Tk::LabEntry;
my $mw = new MainWindow;
foreach $item (@labels){
my $f = $mw->Frame(-bd =>2);
my $e = $f->Entry(-relief =>'sunken',-width => 60);
my $l = $f->Label(-text => $item, -width=>20);
$efeld{$item} = $e;
$l->pack(-side => 'left');
$e->pack(-side => 'right');
$f->pack(-side => 'top', -fill => 'x');
$e->focus if $item eq 'Name:';
}
my $getentry = $mw -> Button (-text => "Get Record",
-command => \&get_record)-> pack;
#
MainLoop;
sub get_record {
my $txt; my %answer;
foreach $item (@labels) {
$txt = ($efeld{$item}) -> get();
$answer{$item}=$txt;
print "$item: $answer{$item}\n";
}
}
###### End Program #############
> So here is a complete little program that makes an entry form and
> fetches the
> entered information back from the entry form so you can save it to a
> file or whatever.
>
> I have made the labels an array so you could load them from a config
> file.
> or from the first line of a dataset.
>
Hi,
why not use, the -textvariable option? Your data model is always in sync -
nothing to worry about:
use warnings;
use strict;
use Tk;
use Data::Dumper;
my @labels =("Name",
"Street Address",
"City",
"State",
"Zip",
"Country",
);
my %data;
my $mw = new MainWindow;
foreach my $item (@labels){
my $f = $mw->Frame(-bd =>2);
my $e = $f->Entry(-relief =>'sunken',
-width => 60,
-textvariable => \$data{$item},
);
my $l = $f->Label(-text => $item, -width=>20);
$l->pack(-side => 'left');
$e->pack(-side => 'right');
$f->pack(-side => 'top', -fill => 'x');
$e->focus if $item eq 'Name:';
}
my $getentry = $mw -> Button (-text => "Get Record",
-command => \&get_record)-> pack;
#
MainLoop;
sub get_record {
print Dumper \%data;
}
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop