jepri has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm running ActiveState Perl 5.6.0 with a very recent version of Tk downloaded by PPM in the last fortnight.

My problem is that I can do this:

my $widget=$toplevel->Listbox(-height=>0,-width=>0)->pack;
And I get a listbox which automatically resizes when the user resizes the $toplevel window. However, when I do this:

my $widget=$toplevel->Scrolled('Listbox', -scrollbars=>'e',-height=>0, + -width=>0)->pack;
I get a listbox that fits neatly into the $toplevel window, but won't resize when I resize the $toplevel window.

I dove into the code for Tk, but it's pretty complicated (to me), and I couldn't even find where to start tweaking. I thought I found a routine in widget.pm, but when I started mucking with it, nothing changed. Does anyone have a solution (apart from fixed size listboxes)? I'd like to avoid binding a subroutine to the resize event on the parent window (if I can even do that in Tk).

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Packing scrolled listboxes in Tk
by azatoth (Curate) on Jan 25, 2001 at 20:10 UTC
    UPDATED
    my $widget = $mainwindow->Scrolled("Listbox", -relief => "sunken", -background => "gray60", -width => 90, -height => 30, ); $widget->pack(-side => "left", -fill => "both", -expand => "yes");


    Azatoth a.k.a Captain Whiplash

    Get YOUR PerlMonks Stagename here!
      Thanks for the try, but that code gives me a listbox with two scrollbars, again nonresizable.

      Update:

      Sorry azatoth, I missed the pack statement you added above, which was correct, as is ichimunki's below.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

Re: Packing scrolled listboxes in Tk
by ichimunki (Priest) on Jan 25, 2001 at 20:49 UTC
    The problem isn't with the Listbox or Scrolled, it's with pack().
    #/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new( -title => 'Test' ); my $listbox = $mw->Listbox() # or ->Scrolled( 'Listbox' ) ->pack( -expand => 1, -fill => 'both' ); my @list = ( qw ( foo bar baz batz dingo dongo dango floo blar blaz blatz zingo zongo zango fi ba be bz uno duo trio quitro ) ); for my $item (@list) { $listbox->insert( 'end', $item ) } MainLoop;