Make a Scrolled Pane. Into the Scrolled Pane, pack a Frame for each row. To each Frame, add your Text widgets, packing left to right. Here is the idea with a bunch of Scrolled Canvases. If you also need to control focus, it is shown too. Of course, for 100 rows, you will need to automate the loop, I just hardwired in 2 Frames. UPDATE: added -expand=>1,-fill=>'both' options to make resizing look nice.
#!/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 $f1 = $mwf->Frame()->pack(-expand=>1,-fill=>'both');
my $f2 = $mwf->Frame()->pack(-expand=>1,-fill=>'both');
my %canv;
for (0..4){
$canv{$_}{'obj'} = $f1->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',
);
my $num = $_;
$canv{$num}{'obj'}->CanvasBind( '<FocusOut>' => sub{
$canv{$num}{'obj'}->configure(-bg=>'lightyellow');
} );
$canv{$num}{'obj'}->CanvasBind( '<FocusIn>' => sub{
$canv{$num}{'obj'}->configure(-bg=>'lightgreen');
} );
}
for (5..9){
$canv{$_}{'obj'} = $f2->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=>'bot
+h');
$canv{$_}{'obj'}->createText(50,50,
-text => $_,
-anchor => 'center',
);
my $num = $_;
$canv{$num}{'obj'}->CanvasBind( '<FocusOut>' => sub{
$canv{$num}{'obj'}->configure(-bg=>'lightyellow');
} );
$canv{$num}{'obj'}->CanvasBind( '<FocusIn>' => sub{
$canv{$num}{'obj'}->configure(-bg=>'lightgreen');
} );
}
my $button = $mw->Button(-text=>'Focus 1',
-command => sub{
$canv{1}{'obj'}->focusForce;
$canv{1}{'obj'}->configure(-bg=>'blue');
})->pack();
MainLoop();
| [reply] [d/l] |
I want it to look like the follow example main windows and row of 5 widgets just add scrollbar that can go up and down
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Pane;
my $mw = MainWindow->new;
$mw->geometry('400x250');
my $mwf = $mw->Scrolled('Pane',
-scrollbars=>'ose',
-sticky=>'nwse',
)->pack(-expand=>1, -fill=>'both');
my $f1 = $mwf->Frame()->pack();
my $f2 = $mwf->Frame()->pack();
my $textTopStart = 328;
my $textTop = $textTopStart;
my $textHeight = 31;
my @textWidth = ("4", "160", "309", "460", "609");
my $dude2 = $mw->Text(-background => 'white', -foreground => 'black'
+,-height => 1,-width => 22)->place( -x => $textWidth
[0], -y => $textTop);
my $dude3 = $mw->Text(-background => 'white', -foreground => 'blac
+k',-height => 1,-width => 21)->place( -x =>
$textWidth[1], -y => $textTop);
my $dude4 = $mw->Text(-background => 'white', -foreground => 'blac
+k',-height => 1,-width => 21)->place( -x =>
$textWidth[2], -y => $textTop);
my $dude5 = $mw->Text(-background => 'white', -foreground => 'blac
+k',-height => 1,-width => 21)->place( -x =>
$textWidth[3], -y => $textTop);
my $dude6 = $mw->Text(-background => 'white', -foreground => 'blac
+k',-height => 1,-width => 22)->place( -x =>
$textWidth[4], -y => $textTop);
$textTop += $textHeight;
MainLoop();
| [reply] [d/l] |
Don't mix, pack and place. Also, trying to maintain pixel positions with place is a losing proposition. Learn to use pack. This is how to do it.
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Pane;
my $mw = MainWindow->new;
$mw->geometry( '400x250' );
my $mwf = $mw->Scrolled(
'Pane',
-scrollbars => 'ose',
-sticky => 'nwse',
)->pack( -expand => 1, -fill => 'both' );
my $f1 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' );
my $f2 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' );
my %dudes;
my $dude_count = 1;
foreach my $fr($f1, $f2){
foreach (1..6){
$dudes{$dude_count}{'text'} = $fr->Text(
-background => 'white',
-foreground => 'black',
-height => 10,
-width => 22
)->pack(-side=>'left', -expand => 1, -fill => 'both' );
$dudes{$dude_count}{'text'}->insert('end', "\n Dude $dude_count\n")
+;
$dude_count++;
}
}
MainLoop();
| [reply] [d/l] |