http://www.perlmonks.org?node_id=942166

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

I have a PerlTk app containing a.o a frame that has 2 Scrolled text boxes in it. To minimize the app, there is a button that can show/hide these boxes. Hitting the button calls a PackForget() on the frame and its children, or a pack() on the same, depending on the state of the frame.

Now this works fine as long as the GUI is not being resized manually. After a resize, the text boxes are forgotten and restored, but the main window does not resize to go with it.

I have trimmed down the code as much as possible (see below), and tried many code changes but can't get around the problem. As such there is some 'debug' code still around.

any help is appreciated, David

my code:
use strict; use Tk; use Tk::Menu; use Tk::Text; use Tk::Dialog; use Tk::Scrollbar; use Tk::DialogBox; ##################### my $stdout_shown = 1; ############ script starts here ################## my $mw = MainWindow->new(); $mw->title($0); my $buttons_frame = $mw->Frame(-relief => 'groove')->pack(-side => ' +top', -fill => 'both'); my $top_frame = $buttons_frame->Frame(-relief => 'groove')->pack +(-side => 'top', -fill => 'x'); my $middle_frame = $buttons_frame->Frame(-relief => 'groove')->pack +(-side => 'top', -fill => 'x'); &load_task_list(); # loads the tasks from the task file and creates a +button for each. &create_ctrl_buttons(); # see how much space is needed without the log_frame $mw->idletasks; my $w = $mw->reqwidth; my $h = $mw->reqheight; print "MINSIZE: $w $h\n"; $mw->minsize($w,$h); $mw->update(); my $log_frame = $mw->Frame(); #$log_frame->packPropagate(1); my $scr_stdout = $log_frame->Scrolled("Text", -scrollbars => 'oso +e',-relief => 'groove', -height => 10)->pack(-fill => 'both', -expand + => 1); my $scr_stderr = $log_frame->Scrolled("Text", -scrollbars => 'oso +e',-relief => 'groove', -height => 5)->pack(-fill => 'both', -expand +=> 1); # -width => 150, $log_frame->pack(-side => 'bottom', -fill => 'both', -expand => 1); $log_frame->packPropagate(1); print STDERR "this is STDERR before tie\n"; print STDOUT "this is STDOUT before tie\n"; MainLoop; exit 0; ################# my @logframe_kids = (); my $stdout_geo; my $stdout_w; my $stdout_h; sub mw_show_hide($) { my $lbtn = $Tk::widget; #$mw->idletasks; my $lframe_w = $log_frame->width; my $lframe_h = $log_frame->height; $stdout_w = $scr_stdout->width; $stdout_h = $scr_stdout->height; $stdout_geo = $scr_stdout->geometry(); # nee +d to adjust for task-bar xx pts my $lframe_rw = $log_frame->reqwidth; my $lframe_rh = $log_frame->reqheight; my $stdout_rw = $scr_stdout->reqwidth; my $stdout_rh = $scr_stdout->reqheight; my $stderr_rw = $scr_stderr->reqwidth; my $stderr_rh = $scr_stderr->reqheight; # warning_window("sizes: frame: c($lframe_w x $lframe_h) r:($lframe_rw + x $lframe_rh) \n stdout: g:($stdout_geo) c($stdout_w x $stdout_h) r( +$stdout_rw x $stdout_rh) \n stderr: $stderr_rw x $stderr_rh"); # print "log-frame " . ($log_frame->ismapped ? 'is' : 'is not') . " ma +pped!\n"; if ($stdout_shown) # it was visible { $stdout_shown = 0 ; # invert the boolean state; hide the window + and add the 'show' button + message $lbtn->configure(-text => 'Show'); @logframe_kids = $log_frame->packSlaves; print "frame slaves:",@logframe_kids,"\n"; foreach (@logframe_kids) { $_->packForget; } $log_frame->packForget; } else { $stdout_shown = 1 ; # invert the boolean state; show the window +and add the 'hide' button + message $lbtn->configure(-text => 'Hide'); print "frame slaves:",@logframe_kids,"\n"; if (scalar(@logframe_kids) == 0) {warning_window("nothing to re-pa +ck here !");} $scr_stdout->configure(-width => $stdout_w , -height => $stdout_h) +; foreach (@logframe_kids) { $_->pack; } $log_frame->pack; } $mw->update; } sub create_ctrl_buttons { my $show_hide_txt = $stdout_shown ? 'Hide' : 'Show'; my $stop_btn = $top_frame->Button(-text => 'Stop', -comma +nd => [\&warning_window, "STOP" ] )->pack(qw/-side left -anchor w/); my $paus_btn = $top_frame->Button(-text => 'Pause', -comma +nd => [\&warning_window, "PAUSE"] )->pack(qw/-side left -anchor w/); my $show_hide_btn = $top_frame->Button(-text => 'Show/hide', -comma +nd => \&mw_show_hide ) ->pack(qw/-side right -anchor e/); } sub load_task_list { my @tsks = qw/t1 t2 t3 t4/; foreach my $t (@tsks) { my $btn = $middle_frame->Button(-width => 4, -text => $t, -comman +d => [\&warning_window ,"$t"] )->pack(qw/-side left -anchor w -fill x + -expand 1/); } } sub warning_window { # print a message and wait for OK to be clicked. my(@args) = @_; my $warn_txt = "WARNING: @args"; my $ww = $mw->Dialog(-title => 'Warning', -text => $warn_txt, -buttons => ['Ok'], -default_button => 'Ok'); my $answer = $ww->Show(); return ($answer); }