#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry(q/600x400+100+100/); $mw->title("Test Script"); #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', 'etc', 'foo','bar','wxyz'); # main Pane for all widget groups my $main_pane = $mw->Scrolled('Pane', -bg=>'black', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); foreach my $choice(@choices){ # main frame for each widget set my $frame = $main_pane->Frame(-bg=>'lightblue') ->pack(-side => 'left', -expand=>1, -fill=>'y'); my $label = $frame->Label(-text=> $choice, -bg=>'hotpink') ->pack(-side=>'top'); $lbhash{ $choice }{'entry'}= $frame->Entry( -bg=>'lightyellow') ->pack(-side=>'top'); $lbhash{ $choice }{'widget'} = $frame->Scrolled('Listbox', -bg => 'white', -selectmode => 'extended', -exportselection=> 0 ) ->pack(-side=>'top', -expand=>1, -fill=>'y'); my @random_data; for(1..20){push @random_data ,int rand(100) } $lbhash{ $choice }{'widget'} ->insert( 'end', @random_data ); } $mw->Button( -text => "Selections", -command => sub{ foreach my $key( keys %lbhash ){ my @selects = $lbhash{ $key }{'widget'}->curselection; print "$key: "; my @inserts; foreach my $select (@selects){ push @inserts, $lbhash{ $key }{'widget'}->get($select); } my $insert_string = join " ", @inserts; $lbhash{ $key }{'entry'}->insert(0, $insert_string); } } )->pack( -side => 'bottom' ); $mw->Button( -text => "Done", -command => \&exit )->pack; MainLoop; #### #!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry('400x250'); my $mwf = $mw->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); my %frame; # hash for holding frames for (1..4){ $frame{$_} = $mwf->Frame()->pack(-expand=>1,-fill=>'both'); } my %canv; for (0..4){ $canv{$_}{'obj'} = $frame{1}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left' ,-padx=>10,-pady=>10, -expand=>1, -fill=>'both'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (5..9){ $canv{$_}{'obj'} = $frame{2}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'lightseagreen', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'both'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (6..10){ $canv{$_}{'obj'} = $frame{3}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'yellow', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'both'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (11..15){ $canv{$_}{'obj'} = $frame{4}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'hotpink', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'both'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } MainLoop();