in reply to Setting the minimum size of an autosized Tk widget
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Setting the minimum size of an autosized Tk widget
by olgo (Sexton) on Dec 10, 2021 at 10:01 UTC |