My Gui is starting to come around, yet I still do not know how to add multiple units of the same widgets row-by-row and then to collect the data en-masse row-by-row. I have been able to pick up all the data from just one row. I am almost there.
Here is the code:
#!C:\Perl64\bin\perl.exe
use strict;
use warnings;
use Tk;
use Tk::Pane;
my $mw = MainWindow->new;
$mw->geometry(q/+100+100/);
$mw->title("Test Script");
$mw->fontCreate('big',
-weight=>'bold',
-size=> 18
);
#need exportselection=>0 for using multiple selection boxes
my %lbhash;
# you want to use the listbox to hold your
# data, so store the widget's actual object
# with the name you want to give it
my @choices = ('afg', 'dfg', 'erty');
my @divisional_unit =('Division Unit Left','Division Unit Middle','Div
+ision Unit Right');
my $text="";
my $count = 0;
my $num=$count++;
my $count1 = 0;
my $num1=$count1++;
my $count2 = 0;
my $num2=$count2++;
my $count3 = 0;
my $num3=$count3++;
my @labels=("Left Text Header", "Middle Text Header", "Right Text Head
+er");
my @labels1=("LC", "MC", "RC");
my @list = ("LC", "MC", "RC");
my %entry;
my $inbox;
my %checkbox;
my $settings;
foreach my $choice(@divisional_unit){
my $pane = $mw->Scrolled('Pane')->pack(-side => 'left');
#create a has for the entry widget
$entry{$labels[$num++]} = $mw->Entry(-textvariable=>$text)->pack(-side
+=>'left');
my $checkbox = $mw -> Checkbutton(-text=>$labels1[$num2++],
-variable=>\$settings->{checkbuttons}->{$list[$num3++]},-offvalue=
+>0,-onvalue=>1)->pack(-side=>'left');
my $label = $pane->Label(-text=> $choice, -bg=>'lightseagreen')
->pack(-side=>'top');
$lbhash{ $choice }{'widget'} = $pane->Listbox(-bg => 'white',
-selectmode => 'extended',
-exportselection=> 0 )->pack(-side=>'bottom');
#my @random_data;
#for(1..20){push @random_data ,int rand(100) }
$lbhash{ $choice }{'widget'} ->insert( 'end', @choices);
#}
}
$mw->Button( -text => "Selections", -command =>
sub{
foreach my $key( sort keys %lbhash ){
my @selects = $lbhash{ $key }{'widget'}->curselection;
print "$key: ";
foreach my $select (@selects){
print $lbhash{ $key }{'widget'}->get($select),' ';
}
print "\n\n";
}
foreach my $key1( sort keys %entry ){
my @selects2 = $entry{$key1}->get();
print "$key1:";
foreach my $s (@selects2) {
print $s,"\n";
}
}
print join( "\n", grep { $settings->{checkbuttons}->{$_}
+} @list );
}
)->pack( -side => 'bottom' );
$mw->Button( -text => "Done", -command => \&exit )->pack(-side=>'botto
+m');
MainLoop;
Thanks for all the wonderful help zentara. |