in reply to Tk configure problem

It may be that you are not showing us enough code to reveal where the problem is.

I was intrigued by the idea of a GUI design where the geometry of certain widgets will change as a result of user (or data) activity at run-time. (Normally, it's not the sort of approach I would recommend -- consistent size and placement of widgets throughout the run-time of the GUI will tend to be an aid to consistent and correct usage. But I can imagine cases where changing the size of a widget dynamically could be useful.)

Anyway, just I wanted to see if I could change the size of a listbox easily, and it seems this is doable:

#!/usr/bin/perl use strict; use Tk; my $mw = MainWindow->new; my $btnframe = $mw->Frame()->pack(-side => 'top'); my $lstframe = $mw->Frame()->pack(-side => 'top'); my $listbox = $lstframe->Listbox(-height => 16, -width => 16)->pack; my @listdata = <DATA>; chomp @listdata; $listbox->insert( 'end', @listdata ); for (qw/5x8 10x10 16x20/) { $btnframe->Button(-text => $_, -command => [ \&resize, $listbox, $_ ], )->pack(-side => 'left'); } MainLoop; sub resize { my ( $lbox, $size ) = @_; my ( $newh, $neww ) = split( /x/, $size ); $lbox->packForget; $lbox->configure(-height => $newh, -width => $neww ); $lbox->pack; } __DATA__ 1234567890123456 ABCDEFGHIJK 1234567890 abcdefghi 12345 stuv foo bar baz junk extra lines last line with no blank following

That's just a simple proof-of-concept, to show that a callback routine (such as would be invoked by a Button widget) can reconfigure the dimensions of a listbox widget.

So the question would be: what is in your code (or missing from your code) that makes it different from this simple example?

Replies are listed 'Best First'.
Re^2: Tk configure problem
by Grygonos (Chaplain) on Jul 15, 2004 at 02:23 UTC
    I can configure it once...via a call to configure.. but the second attempt changes nothing visually... calling cget('height') reveals that the property was set as I asked it to be.. but visually its the same size.
      Well, the sample code I posted above does not seem to have this "one-time-only" limitation, so the question I posed there is still relevant. Are you sure your "re-configure" sub is being called when you expect it? Running Tk under the perl debugger can be very slow, but it might be worth a try -- put a breakpoint in the sub that resizes the listbox, and see whether the script always stops when you think it should. (And check variables while you're there, to make sure they contain what you expect.)