Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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();

In reply to Controlling resize of Tk::Panedwindow by hv

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found