in reply to Re: Tk autosizing Scrolled widgets
in thread Tk autosizing Scrolled widgets

It seems that my original post lacked a bit of context so I will give it some more effort here:
The code example I posted was simply an effort to reduce the problem to highlight the issue I was having, i.e. the autosizing of the variable grid data.

My entire GUI consist of many more elements, but the rest I have already got working, at least sufficiently.

The screen consists of a starting upper left block of widgets; Labels, Entrys, Checkboxes, BrowseEntrys and ProgressBars. Nothing strange there.
Then comes the varying part of the GUI: A grid (based on an HList in my case) that contains all the dynamic data, in response to what the user does with the top widgets.
My dynamic grid consists of lines of varying column content, Entries, Labels, BrowseEntrys and Checkboxes, all with varying dimensions.
In the case where the dynamic grid contains only a limited amount of data, I want all the data to be visible, no scrollbars and the outer window tightly snug around the entire GUI.
In the case where the dynamic grid contains massive amounts on data, I want as much data as possible to be visisble and scrollbars available to be able to scroll the dynamic grid data. The outer window should in this case extend to the entire screen (width/height wise depending on which direction the data extends)

tybalt89: Thanks for the alternative method of producing the grid data. I considered this method before but discarded it due to having to use the grid packing method.
There was a note somewhere saying one should avoid mixing packing methods and I have used only form so far (not pack as in my example). However, seeing your example code, I will definately have a go at it.
Your code example however still produces scrollbars when adding more data in the grid (Even your example code produces a horizontal one).

Marshall:You code does solve the problem.
Enlarging the window by means of changing the window MinSize is however not what I want (I want the user to be able to resize it at will), but -configuring the scrolled pane size worked equally well.

Conclusion
If this is indeed the best/only solution, I will have to sum up the total of all my top widgets and dynamic grid contents.
I still have the feeling that there should be some neat Tk packing or whatever mechanism for doing this but maybe there isn't.
Giving this type of task to the "application" seems wrong. Best solution would be to add this as a new option to the packer algorithm. Maybe this could be added as a Tk request somewhere?

Getting answers (and even programming efforts) to my question in less than 24h is way more than I expected.
Thank you all.

Replies are listed 'Best First'.
Re^3: Tk autosizing Scrolled widgets
by tybalt89 (Monsignor) on Sep 14, 2021 at 08:41 UTC

    The mixing of ->pack and ->grid only applies within ONE parent, different parents can have different geometry managers within one application. No Problem. I do it all the time. Example follows.

    Applications resizing themselves without user input is a BAD IDEA. Just imagine your user trying to click on something and having it move out of the way just before the click. BAD IDEA!

    See the "widget" demo program for an example of what an HList looks like. It should have come with the Perl/Tk package.
    "I do not think it means what you think it means."

      tybalt89:contrary to your strong recommendation, my application DOES NOT resize itself without user input. It reacts on user input and thus gets more or less data to present. Maybe I was unclear about this.
      By the way, the widget demo, specifically the HList one was what made me choose this Grid mechanism in the first place. But, as I also wrote before, I will give your ->grid packer a go, now that I now that it is an alternative. (The HList does do the job though, but there might be overhead)
      Thanks!

        Maybe closer, maybe not...
        Fine tuning left to the OP.

        #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11136705 use warnings; use Tk; use Tk::Pane; my ($rows, $columns) = (11, 13); my $sbsize = 22; my $mw = MainWindow->new(); # example of ->pack in a different Frame my $buttonbar = $mw->Frame(-bg => 'blue', )->pack(-fill => 'x'); $buttonbar->Button(-text => 'Exit', -command => sub{$mw->destroy}, )->pack(-side => 'right', -fill => 'x', -expand => 1); $buttonbar->Button(-text => 'Set Size', -command => \&setsize, )->pack(-side => 'right', -fill => 'x', -expand => 1); $buttonbar->Button(-text => 'Remove Column', -command => sub{$columns--; changegrid(); setsize(); }, )->pack(-side => 'right', -fill => 'x', -expand => 1); $buttonbar->Button(-text => 'Add Column', -command => sub{$columns++; changegrid(); setsize(); }, )->pack(-side => 'right', -fill => 'x', -expand => 1); $buttonbar->Button(-text => 'Remove Row', -command => sub{$rows--; changegrid(); setsize(); }, )->pack(-side => 'right', -fill => 'x', -expand => 1); $buttonbar->Button(-text => 'Add Row', -command => sub{$rows++; changegrid(); setsize(); }, )->pack(-side => 'right', -fill => 'x', -expand => 1); my ($screenw, $screenh) = ($mw->screenwidth, $mw->screenheight); print "w $screenw h $screenh\n"; $mw->maxsize($screenw, $screenh); #$mw->maxsize(1000,1200); #$mw->minsize(400,300); my $scroll = $mw->Scrolled('Pane', -scrollbars => 'osoe', -sticky => 'news', )->pack(-expand => 1, -fill => 'both'); my $f = $scroll->Frame->pack(-expand => 1, -fill => 'both'); changegrid(); $mw->update; setsize(); MainLoop; -M $0 < 0 and exec $0; # FIXME for testing sub setsize { $mw->update; my( $mwh, $sh, $fh) = map $_->height, $mw, $scroll, $f; my( $mww, $sw, $fw) = map $_->width, $mw, $scroll, $f; my( $mwrh, $srh, $frh) = map $_->reqheight, $mw, $scroll, $f; my( $mwrw, $srw, $frw) = map $_->reqwidth, $mw, $scroll, $f; my $deltaheight = $sh - $frh; my $deltawidth = $sw - $frw; print "height $mwh $mwrh $sh $srh $fh $frh\n"; print " width $mww $mwrw $sw $srw $fw $frw\n"; print "delta h $deltaheight w $deltawidth\n"; my $geo = $mw->geometry; my ($w, $h) = split /\D/, $geo; my $newgeo = ($w - $deltawidth + $sbsize + 10) . 'x' . ($h - $deltaheight + $sbsize); print "old $geo new $newgeo\n"; $mw->geometry( $newgeo ); } sub changegrid { $_->destroy for $f->children; foreach my $row (0..$rows - 1) { foreach my $col (0..$columns - 1) { $f->Entry( -text => "rc $row $col", -width => 0, )->grid(-row => $row, -column => $col, -sticky => 'news'); $row or $f->gridColumnconfigure($col, -weight => 1); } $f->gridRowconfigure($row, -weight => 1); } }