perlquestion
hv
<p>I am very new to Tk - and to anything graphical in general - so I may well be missing fundamentals.</p>
<p>I'm trying to create a view showing a fragment of a larger world (A), with a pane below for control options (C), and a pane to the right showing details of an element in the world (B):<p>
<pre>
+-------+---+
| | |
| A | B |
| | |
+-------+---+
| C |
+-----------+
</pre>
<p>I'm using a horizontal Panedwindow for A, B, and a vertical Panedwindow for A+B, C, so the user can control the width of B and the height of C. When the window is resized, I want the width of B and height of C to stay constant, and the primary window A to shrink or grow as needed, hopefully with some event I can bind to update its contents. However the opposite is happening: A stays constant, and the other two resize.</p>
<p>I suspect this is the nature of a Panedwindow: if I swap the order I add A and B to the upper pane, for example, the size of B stays fixed on resizing (but it's now on the left). However I don't see anything in the docs for Panedwindow to control this, nor do I see in the code how it handles resizing events. Can someone suggest how to achieve the effect I want?</p>
<p><b>Update</b>: as pointed out by [choroba], this <i>is</i> the nature of a Panedwindow. So can someone point to how that is implemented, so I can create a variant of a different nature?</p>
<p><b>Another update</b>: in Tk-8.5, panes in a Panedwindow acquired a new <i>stretch</i> attribute that controls how new space is allocated among them. 8.5 also includes ttk, which has its own variant of Panedwindow; this one lets you specify a <i>weight</i> attribute on panes for even finer-grained control. Current Perl-Tk is based on Tk-8.4, so I guess I need to go bug Slaven. I did this in <a href="https://github.com/eserte/perl-tk/issues/75">issue 75</a>, which got a comment from [chrstphrchvz].</p>
<p><b>More</b>: [tybalt89]++ offered a solution in [id://11129054] which looks to do exactly what I want; I'll be going with that for now. An [Anonymous monk] looking a lot like [zentara] also pointed me at a couple of alternative Panedwindow implementations in [id://11128980], but the one of those I looked at seems quite buggy. [kcott] also offered a decent cut-down solution in [id://11129002] if I didn't mind losing the user-controllable aspect of paned windows.</p>
<p>Hugo</p>
<code>
#!perl
use strict;
use warnings;
use Tk;
my $main_window = MainWindow->new;
my $top_container = $main_window->Panedwindow(-orient => 'vertical');
$top_container->pack(
-side => 'top',
-expand => 'yes',
-fill => 'both',
-padx => '2m',
-pady => '2',
);
my $world_container = $top_container->Panedwindow(-orient => 'horizontal');
$world_container->pack(
-side => 'top',
-expand => 'yes',
-fill => 'both',
-padx => '2',
-pady => '2m',
);
$top_container->add($world_container);
my $world_view = $world_container->Canvas();
$world_view->pack(
-side => 'left',
-fill => 'both',
-expand => 1,
);
$world_container->add($world_view);
my $entity_view = $world_container->Frame();
$entity_view->pack(
-side => 'right',
-fill => 'y',
-expand => 0,
);
$world_container->add($entity_view);
my $control_view = $top_container->Frame;
$control_view->pack(
-side => 'bottom',
-fill => 'x',
-expand => 0,
);
$top_container->add($control_view);
my $quit_button = $control_view->Button(
-text => 'Quit',
-command => sub { $main_window->destroy },
);
$quit_button->pack(
-side => 'right',
-expand => 'no',
-pady => 2,
);
Tk::MainLoop();
</code>