I think that you have the first part, that the scrollbars disappear when they are not necessary.

I think what you want is: When the display pops up onto the screen, it should use the entire height and width of the monitor and not have any scrollbars unless they are necessary? Since you have solved the first part of the problem (scrollbars disappear if the aren't needed). This comes down to the equivalent requirement of how to size the window so that you can see everything without scrollbars, if possible?

There isn't any pack() parameter, to my knowledge that says "use entire screen space".
I think you will have to calculate your "ideally" required space (height and width in pixels), and compare that with the pixel resolution of the monitor that you are running on. If there aren't enough pixels available, then the best that you can do is have a window of the max monitor's pixel width.

These functions are available:

$widget->reqheight #requested height $widget->height #actual height $widget->reqwidth #requested width $widget->width #actual width
It been a very long time since I worked with Tk. I'm not familiar with some of the widgets that you used, so I wrote my own example to play with.

What I wanted to show is how to count up pixel widths of objects and then use that total to configure the window size. For some reason the configure method didn't work in my testing, but but I'm sure that is some kind of brain cramp on my part. I just set the minimum width of the window to size needed for the columns shown. I added a 20 pixel "fudge factor" at the end of the row to account for the scroll bars in my example which work differently than yours. I just did the width calculation, but height would be similar.

Anyway here is my hacking code for further thought..

use Tk; use Tk::Pane; use strict; use warnings; my $Window = MainWindow->new(); $Window->geometry("+0+0"); # start in upper left corner of display my $sframe = $Window; my $scroll = $sframe->Scrolled('Pane', -sticky => 'news', -scrollbars => 'se', ); $scroll->pack(-expand => 1, -fill => 'both');; my $total_row_width = 0; foreach my $row (0..9) { my $row_frame = $scroll->Frame()->pack(-side=>'top',-fill=>'x'); $total_row_width = 0; foreach my $col (0..12) { my $this_entry =$row_frame -> Entry(-text => "Whatever $row,$co +l", -width => 12)->pack(-side = +> 'left'); my $width_this_widget = $this_entry->reqwidth; $total_row_width += $width_this_widget; } #print "width in pixels this row of widgets: $total_row_width\n"; } my $fudge = 20; print "total row width = $total_row_width\n"; $Window->minsize($total_row_width + $fudge,300); MainLoop;
You will of course have to figure out the pixel width of the monitor that you are running upon. But that is not a Tk function to my knowledge.
Also be aware that Tk sometimes uses "width in characters" instead of pixels. But that is only an approximate measure (see my width of Entry window).

In reply to Re: Tk autosizing Scrolled widgets by Marshall
in thread Tk autosizing Scrolled widgets by olgo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.