=?UTF-8?Q?Josef_M=C3=B6llers?= <
josef@invalid.invalid> wrote or quoted:
What do I need to do to have all the widgets grow to fill the large >MainWindow?
An example is provided below; see the comments.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
sub say_hello { print "Hello!\n"; }
sub say_goodbye { print "Goodbye!\n"; }
my @items = (
[ 'hello_btn', 'Say Hello', \&say_hello ],
[ 'goodbye_btn', 'Say Goodbye', \&say_goodbye ],
);
my $MAXCOLUMNS = 2;
my $mw = MainWindow->new;
$mw->title("Resizable Button Grid Example");
my %button;
my ($row, $col) = (0, 0);
foreach my $item (@items) {
my $name = shift @$item;
my $label = shift @$item;
my $func = shift @$item;
$button{$name} = $mw->Button(
-text => $label,
-command => [ $func, @$item ]
)->grid(
-row => $row,
-column => $col,
-sticky => 'nsew' # allow widget to stretch in all directions
);
$mw->gridColumnconfigure($col, -weight => 1); # make this column expand when window grows
$col++;
if ($col == $MAXCOLUMNS) {
$mw->gridRowconfigure($row, -weight => 1); # make this row expand when window grows
$row++;
$col = 0;
}
}
if ($col != 0) {
$mw->gridRowconfigure($row, -weight => 1); # expand last partially filled row
$row++;
}
my $status = $mw->Entry(-relief => 'sunken')->grid(
-row => $row,
-column => 0,
-columnspan => $MAXCOLUMNS,
-sticky => 'nsew' # entry expands across both directions
);
$mw->gridRowconfigure($row, -weight => 1); # let status row expand
$row++;
my $erase_after_copying = 0;
$mw->Checkbutton(
-text => "Erase after copying",
-variable => \$erase_after_copying
grid(
-row => $row,
-column => 0,
-columnspan => $MAXCOLUMNS,
-sticky => 'nsew' # checkbox expands with resizing
);
$mw->gridRowconfigure($row, -weight => 1); # let this row expand
$row++;
$mw->Button(
-text => 'Shutdown',
-command => sub { system("sudo poweroff") }
grid(
-row => $row,
-column => 0,
-columnspan => $MAXCOLUMNS,
-sticky => 'nsew' # shutdown button stretches
);
$mw->gridRowconfigure($row, -weight => 1); # let shutdown row expand
MainLoop;
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)