note
thundergnat
<p>You don't want to (can't actually) scroll the main window directly. You need to insert a scrolled Frame or Pane into the toplevel (main window) then pack your widgets inside that.</p>
<c>
use strict;
use warnings;
use Tk;
use Tk::Pane;
my %w;
$w{mw} = MainWindow->new;
$w{mw}->geometry('220x350');
$w{bframe} = $w{mw}->Scrolled(
'Frame',
-scrollbars => 'oe'
)->pack(
-expand => 1,
-fill => 'both'
);
for (qw/ this that a_longer_name X cheese verb witty_retort superstition A..Z whatever/){
my $bttn = $w{bframe}->Button(
-text => "$_",
-font => 'times 19',
-justify => 'left',
-compound => 'right',
-bitmap => ('error','info','question','warning')[rand 4],
-anchor => 'e',
-padx => 4,
)->pack;
push @{$w{buttons}}, $bttn;
}
$w{mw}->update;
{
my $width = 0;
for (@{$w{buttons}}) {
$width = $_->width if $_->width > $width;
}
for (@{$w{buttons}}) {
$_->configure(-width => $width);
}
}
MainLoop;
</c>
1037479
1037522