Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

button disappears on resize? how to prevend

79 views
Skip to first unread message

ruud144

unread,
Mar 14, 2013, 7:10:22 AM3/14/13
to
hello group,

I need a short explanation about the behaviour of my script. It has
two listboxes next to each other and to buttons beneath it. The
listboxes should get a scrollbar when necessary. When testing that (it
works indeed), I saw that the listboxes only shrink and get a
scrollbar after the buttons were disappeared from the window.

I made a simple form of the script (one listbox and one button) to
show the behaviour.
My questions: what can I do about it, and more important: who can
explain what is going on. I have the Perl/Tk book; a pointer to the
right paragraph is welcome too.

thanks in advance, Ruud


use Tk::widgets qw (Listbox Button);
#!/usr/bin/perl
use strict;
use Carp;

use Tk::widgets qw (Listbox Button);

my $top = MainWindow->new();
my $button = $top->Button (-text => 'ok', -command => sub {exit
(0)});
my $listframe = $top->Frame ( -borderwidth => '2', -relief =>
'raised');
$listframe->pack(-expand => '1', -fill => 'both', -side =>
'top',);

my $lb = $listframe->Scrolled ('Listbox', -scrollbars => 'ow',
-selectmode => 'extended',
-label => 'test',
-takefocus => 1);
foreach (1..13) { $lb->insert ('end', "entry$_"); }
$lb->pack ( -side => "left", -fill => "both", -expand =>
'yes');


$button->pack ( -side => "bottom", -fill => "x", -expand =>
'1');

Tk::MainLoop();

ruud144

unread,
Mar 14, 2013, 7:16:29 AM3/14/13
to
On Mar 14, 12:10 pm, ruud144 <r.grosm...@gmail.com> wrote:
> My questions: what can I do about it, and more important: who can
> explain what is going on. I have the Perl/Tk book; a pointer to the
> right  paragraph is welcome too.

Maybe it is not clear from the question, but I want the buttons to
stay in the window as long as possible. I want the list to be resized
rather than the button be pushed out of the window.

thanks, Ruud

ruud144

unread,
Mar 14, 2013, 9:31:52 AM3/14/13
to
I found out it has to do with the packing order. In order to get the
behaviour I want, I have to pack the button before the frame with the
list in it is packed.

Ruud

Horst-W. Radners

unread,
Mar 14, 2013, 9:54:28 AM3/14/13
to
ruud144 schrieb am 14.03.2013 14:31:> On Mar 14, 12:16 pm, ruud144
You are right, the packing order determines which widget disappears first.
But please note, that for the initial size of the whole window and a
clean behaviour on resizing (reduce and enlarge!), you should use
appropriate
combinations of the -side, -anchor, -fill and -expand options.
Moreover esp. listboxes have a -height option for the initial nb of lines.

#!/usr/bin/perl
use warnings;
use strict;

use Tk::widgets qw(Listbox Button);

my $top = MainWindow->new();

my $button = $top->Button(
-text => 'ok',
-command => sub {
exit(0);
})->pack(
-side => 'bottom',
-anchor => 's',
-fill => 'x',
-expand => '0' );

my $listframe = $top->Frame(
-borderwidth => '2',
-relief => 'raised',
)->pack(
-expand => '1',
-fill => 'both',
-side => 'top', );

my $lb = $listframe->Scrolled(
'Listbox',
-scrollbars => 'ow',
-selectmode => 'extended',
-label => 'test',
-takefocus => 1,
-height => 8,
)->pack(
-side => 'top',
-anchor => 'nw',
-fill => 'both',
-expand => '1' );
foreach ( 1 .. 13 ) { $lb->insert( 'end', "entry$_" ); }

Tk::MainLoop();

HTH, Horst
--
<remove S P A M 2x from my email address to get the real one>
0 new messages