G'day olgo,

"I am using pack geometry manager since my surrounding widgets are of varying size and type (Progressbars, buttons etc)."

That sounds like you're making assumptions, and at least some of them are incorrect. Please explain that statement in more detail.

"Thus, using another geo manager like grid is not possible in this case (I know that this is one solution to the problem)."

It can't be "not possible" and, simultaneously, a "solution to the problem": they're mutually exclusive. Perhaps a typo or just badly worded.

You seem to be saying that you can't use pack() and grid() in the same Tk application. If so, that's incorrect (see my code below); if not, please be a bit more specific about what you mean.

"My problem is that the top (LabEntry) subwidget, which presents the currently selected entry, gets too small when displaying really small values."

I ran your sample code and couldn't replicate that problem. In "Tk::Entry - Switch:-width", you'll see "average-size characters of the widget's font". If the entry is the smallest, i.e. one character, then "l" would probably be less than the average, and "W" would likely be greater. I'd normally add a couple of characters to the widest expected string. The reason that I can't reproduce this issue, could be as simple as us having different default fonts; or our X servers rendering the same font slightly differently.

"I have realized that I can either set a dynamic width using -width => 0 (works perfectly except for small values being barely visible) or a fixed width (works perfectly except large values are cropped)."

See my last point re the small values. For large values, they may looked cropped but they aren't. Running your example code and selecting your long entry, I see "LargeEnoug" (which fits with -width => 10). Dragging the mouse cursor to the right, reveals more characters to the right while an equivalent amount is hidden on the left; e.g. "geEnoughTo". You can get the same effect by placing the insertion cursor in the text, then using the left and right arrow keys.

"Is there any way of stating a minimum size to the top widget so that it does not autosize smaller than this value, or is there some other mechanism I could use here?"

The biggest problem that I saw with your sample code was the GUI dimensions wildly jumping from one extreme to the other. This is not a good UX solution and I would recommend dropping the idea of autosizing.

If your list is static, or has all entries of the same width, you can just add a -width value yourself. If your list is dynamic, use a solution along the lines that ++Discipulus presented.

Take a look at the code below. You didn't provide sufficient up-front information, so this is just an example with suggestions. Here's a brief outine of some of its features:

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw = MainWindow::->new(); $mw->geometry('400x200'); my $layout_F = $mw->Frame( )->pack(-expand => 1, -fill => 'both'); my $layer1_F = $layout_F->Frame()->pack(); my $layer2_F = $layout_F->Frame()->pack(); my $be_F = $layer1_F->Frame( )->pack(-side => 'left', -anchor => 'n'); my $w_right_F = $layer1_F->Frame( )->pack(-side => 'left', -anchor => 'n'); my $w_bottom_F = $layer2_F->Frame( )->pack(); my $be1 = $be_F->BrowseEntry(-label => 'Misc1: ', -width => 35); $be1->pack(-anchor => 'w'); $be1->insert("end", "0"); $be1->insert("end", "LargeButWillStillFitInTopWidgetAsItExpands"); my $be2 = $be_F->BrowseEntry(-label => 'Misc2: ', -width => 35); $be2->pack(-anchor => 'w'); $be2->insert("end", "0"); $be2->insert("end", "Large"); $be2->insert("end", "LargeEnoughToNotFitInTopWidget"); $w_right_F->Label(-text => 'Label 1')->grid(); $w_right_F->Label(-text => 'Label 2')->grid(); $w_bottom_F->Button( -text => 'Exit', -command => sub { exit }, )->pack(); MainLoop;

— Ken


In reply to Re: Setting the minimum size of an autosized Tk widget by kcott
in thread Setting the minimum size of an autosized Tk widget 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.