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

Monks, *huff* *pant* *wheeze*

I have a problem that is driving me insane. I have a Tk::Listbox that I'm passing around to different routines. These routines call

$widget->configure(-height=>X, -width=>Y);
This works. It reconfigures the height and width properly. I can configure it pack it, packForget it, reconfigure it and repack it, and it works when calling it inside the same sub.
#Create a scrolled listbox $list->configure(-height=>12, -width =>12); #Populate the scrolled listbox with tape numbers $list->insert('end',$_) for @tapes; $list->pack(); + $list->packForget(); $list->configure(-height=>12, -width =>100); $list->pack();
(i.e. I thought it might be once its packed once those options can't be changed). After each subroutine uses the list I call this routine.
sub initList { my $list = shift; #Remove the list from the packing order $list->packForget(); #Remove all elements from the list $list->delete('end') for(0..$list->size); print $list->cget('height'); #Reset heigth and width $list->configure(-height=>1, -width =>1); #Unbind the double click binding $list->bind('<Double-1>',''); return; }
So that the next sub that uses it must configure it the way it likes or be stuck with default values. When my next sub gets the reference passed to it like so,
sub listData { my ($client,$dbh,$dlg,$list) = @_; #retrieve a list of tapeID numbers for a client my @tapes = getTapes($client,$dbh); #Create a DialogBox $dlg->configure(-title=>"Tapes for ".$$client); $dlg->Subwidget('B_1')->configure(-text=>'OK'); $dlg->Subwidget('B_0')->packForget(); #Create a scrolled listbox $list->configure(-height=>12, -width =>12); #Populate the scrolled listbox with tape numbers $list->insert('end',$_) for @tapes; $list->pack(); + #Show the dialog $dlg->Show(); initDialog($dlg); initList($list); return; }
The size of the listbox is not 12 and 12 (although cget'ing the widget says its 12) The size displayed on screen is still the 20x30 that was configured in the subroutine before hand.

Conversely, if I call this routine first and set it to 12 and 12, the routine that attempts to configure the listbox at 20x30 still shows it at 12x12, and cget'ing those options says 20 and 30

What is going on Monks? Any help?

Grygonos

Replies are listed 'Best First'.
Re: Tk configure problem
by graff (Chancellor) on Jul 15, 2004 at 01:21 UTC
    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:

    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?

      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.)
Re: Tk configure problem
by eserte (Deacon) on Jul 15, 2004 at 09:35 UTC
    Maybe you need to turn geometry propagation off?
    $mw->packPropagate(0)