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

Hello.

How could I place the four panes in 2 rows and 2 columns using the pack geometry manager?

I have tried all options described in Chapter 2, Figure 15, of Mastering Perl/Tk, nothing helped.

Example:

------------------ | | | | A | B | | | | ------|----------| | | | | | | | C | D | | | | | | | ------------------

Thanks.

Janitors removed link to pirated material.

Replies are listed 'Best First'.
Re: A question regarding Perl::Tk, pack
by graff (Chancellor) on Mar 30, 2016 at 01:11 UTC
    The sample code posted by beech above shows how to use "pack" to get four panes arranged in the 2x2 pattern you want.

    But personally, for this sort of thing, I'd use the "grid" geometry manager:

    #!/usr/bin/perl use strict; use warnings; use Tk qw/tkinit/; my $mw = Tk::MainWindow->new; my $topleft = $mw->Pane(qw'-bg pink' )->grid(qw/ -column 0 -row 0 / +); my $topright = $mw->Pane(qw'-bg purple' )->grid(qw/ -column 1 -row 0 / +); my $botleft = $mw->Pane(qw'-bg green' )->grid(qw/ -column 0 -row 1 / +); my $botright = $mw->Pane(qw'-bg orange' )->grid(qw/ -column 1 -row 1 / +); $mw->MainLoop;
    So, what did you actually try that was different from either of these two examples?
      Yeah, it is easier. I just couldn't understand how to do it with pack...
Re: A question regarding Perl::Tk, pack (four panels four square)
by beech (Parson) on Mar 30, 2016 at 00:05 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Tk qw/ tkinit /; my $mw = Tk::MainWindow->new; my $top = $mw->Frame(qw'-bg red' )->pack(qw/ -expand 1 -fill b +oth -side top /); my $bottom = $mw->Frame(qw'-bg blue' )->pack(qw/ -expand 1 -fill +both -side bottom /); my $topleft = $top->Pane(qw'-bg pink' )->pack(qw/ -expand 1 -fill +both -side left /); my $topright = $top->Pane(qw'-bg purple' )->pack(qw/ -expand 1 -fil +l both -side right /); my $botleft = $bottom->Pane(qw'-bg green' )->pack(qw/ -expand 1 -f +ill both -side left /); my $botright = $bottom->Pane(qw'-bg orange' )->pack(qw/ -expand 1 - +fill both -side right /); $mw->MainLoop;
      Aha! The trick was in creating 2 frames-containers. The first for A, B and the second for C, D. And I was wasting time trying to do the same with one frame-container (not possible with pack?).

        And I was wasting time trying to do the same with one frame-container (not possible with pack?).

        No, I dont think its possible,

        the docs say Tk::pack - Geometry manager that packs around edges of cavity, a geometry manager that arranges the children of a parent by packing them in order around the edges of the parent.

        Once the Panes are arranged on the edges, two on top and two on bottom, there is no option for them to be expanded half way, so they'll either be stacked vertically or horizontally

Re: A question regarding Perl::Tk, pack
by Anonymous Monk on Mar 29, 2016 at 20:14 UTC
    when you say you've tried everything, show code
      I tried too many variants to show them all...

        Just show one variant, the one that seemed to come closest to what you want. Ideally, it should be a very simple app, maybe just four Buttons that each have unique text, but do nothing when clicked. Post it in the main line of this thread.


        Give a man a fish:  <%-{-{-{-<