http://qs1969.pair.com?node_id=11128956

hv has asked for the wisdom of the Perl Monks concerning the following question:

I am very new to Tk - and to anything graphical in general - so I may well be missing fundamentals.

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):

  +-------+---+
  |       |   |
  |   A   | B |
  |       |   |
  +-------+---+
  |     C     |
  +-----------+

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.

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?

Update: as pointed out by choroba, this is the nature of a Panedwindow. So can someone point to how that is implemented, so I can create a variant of a different nature?

Another update: in Tk-8.5, panes in a Panedwindow acquired a new stretch 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 weight 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 issue 75, which got a comment from chrstphrchvz.

More: tybalt89++ offered a solution in Re: Controlling resize of Tk::Panedwindow 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 Re: Controlling resize of Tk::Panedwindow (IDELayout IDEpanedwindow), but the one of those I looked at seems quite buggy. kcott also offered a decent cut-down solution in Re: Controlling resize of Tk::Panedwindow if I didn't mind losing the user-controllable aspect of paned windows.

Hugo

#!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 => 'horizont +al'); $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();