Groups | Search | Server Info | Login | Register
Groups > comp.lang.perl.tk > #282
| From | ram@zedat.fu-berlin.de (Stefan Ram) |
|---|---|
| Newsgroups | comp.lang.perl.tk |
| Subject | Re: Maximize widget sizes |
| Date | 2025-08-16 22:16 +0000 |
| Organization | Stefan Ram |
| Message-ID | <example-20250816231533@ram.dialup.fu-berlin.de> (permalink) |
| References | <mgc9pcFhg8jU1@mid.individual.net> |
=?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;
Back to comp.lang.perl.tk | Previous | Next — Previous in thread | Next in thread | Find similar
Maximize widget sizes Josef Möllers <josef@invalid.invalid> - 2025-08-16 22:59 +0200
Re: Maximize widget sizes ram@zedat.fu-berlin.de (Stefan Ram) - 2025-08-16 22:16 +0000
Re: Maximize widget sizes Josef Möllers <josef@invalid.invalid> - 2025-08-17 10:16 +0200
csiph-web