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


in reply to Controlling resize of Tk::Panedwindow

Hi

Try Tk::IDElayout it provides a https://metacpan.org/pod/Tk::IDEpanedwindow#expandfactors

Its not exactly perfect but try it out

#!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::IDEpanedwindow; my $main_window = MainWindow->new( -bg => 'black' ); my $top_container = $main_window->IDEpanedwindow( qw/-orient vertical -sashpad 1 -sashwidth 3 -sashrelief groove -bg red/); $top_container->pack( -side => 'top', -expand => 'yes', -fill => 'both', -padx => '2m', -pady => '2', ); my $world_container = $top_container->IDEpanedwindow( qw/-orient horizontal -sashpad 1 -sashwidth 3 -sashrelief groove -bg green / ); $world_container->pack( -side => 'top', -expand => 'yes', -fill => 'both', -padx => '2', -pady => '2m', ); $top_container->add( $world_container, -expandfactor, 1, ); my $world_view = $world_container->Canvas( -bg => 'orange' ); $world_view->pack( -side => 'left', -fill => 'both', -expand => 1, ); ## sometimes factor 3 is too much, sometimes not enough # $world_container->add($world_view , -expandfactor,3 ); $world_container->add( $world_view, -expandfactor, 10 ); my $entity_view = $world_container->Frame( -bg => 'blue', ); $entity_view->pack( -side => 'right', -fill => 'y', -expand => 0, ); $world_container->add( $entity_view, -expandfactor, 1, -minsize => 100 ); # SASH limits); my $control_view = $top_container->Frame( -bg => 'yellow', ); $control_view->pack( -side => 'bottom', -fill => 'x', -expand => 0, ); $top_container->add( $control_view, -expandfactor, 1, -minsize => 60 ); # SASH limits); my $quit_button = $control_view->Button( -text => 'Quit', # -command => sub { $main_window->destroy }, # -command => ['destroy', $main_window ], -command => 'exit', ); $quit_button->pack( -side => 'right', -expand => 'no', -pady => 2, ); $main_window->WidgetDump if @ARGV; Tk::MainLoop();

Panedwindow provides a minsize sash resizing limit, but IDEpanedwindow doesnt

Another thing to try is https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_panedwindow.htm somehow, as it has a "weight" option,

which you can try by way of https://metacpan.org/pod/Tcl::pTk

but to me it seems to be similarly funky as expandfactors

Both can be made to do what you want but its fiddly , factors need to adjusted (factored) based on window size, and minimum sizes pre-set and enforced ... I leave that up to you

#!/usr/bin/perl -- use strict; use warnings; use Tcl::pTk::TkHijack; use Tk; my $main_window = MainWindow->new( -bg => 'black' ); my $int = $main_window->interp; # Get the intepreter that was created in the MainWindow call $int->Eval(<<'__TCL__'); ttk::panedwindow .top_container -orient vertical ttk::panedwindow .world_container -orient horizontal -height 100 ttk::style configure . -background black ## fail ttk::style configure .top_container -background red ttk::style configure .world_container -background green __TCL__ my $top_container = $int->widget('.top_container'); # fail #~ $top_container->configure(qw/-background red /); my $world_container = $int->widget('.world_container'); $top_container->pack( -side => 'top', -expand => 'yes', -fill => 'both', -padx => '2m', -pady => '2', ); $world_container->pack( -side => 'top', -expand => 'yes', -fill => 'both', -padx => '2', -pady => '2m', ); $top_container->add( $world_container, -weight, 2 ); my $world_view = $world_container->Canvas( -bg => 'orange' ); $world_view->pack( -side => 'left', -fill => 'both', -expand => 1, ); $world_container->add( $world_view, -weight, 30 ); my $entity_view = $world_container->Frame( -bg => 'blue', ); $entity_view->pack( -side => 'right', -fill => 'y', -expand => 0, ); $world_container->add( $entity_view, -weight, 2 ); my $control_view = $top_container->Frame( -bg => 'yellow', ); $control_view->pack( -side => 'bottom', -fill => 'x', -expand => 0, ); $top_container->add( $control_view, -weight, 2 ); my $quit_button = $control_view->Button( -text => 'Quit', -command => [ 'destroy', $main_window ], ); $quit_button->pack( -side => 'right', -expand => 'no', -pady => 2, ); Tk::MainLoop();

*) the labels ought to match the variable names (A B C does not match world_view...), its like labeling a red window orange

Replies are listed 'Best First'.
Re^2: Controlling resize of Tk::Panedwindow (IDELayout IDEpanedwindow)
by chrstphrchvz (Scribe) on Mar 03, 2021 at 06:17 UTC

    Current Tk::IDElayout and Tcl::pTk maintainer here. If one can get their program working with Tcl::pTk, I would probably prefer that approach over using Tk::IDElayout (which is somewhat neglected).

    For the Tcl::pTk approach suggested here, using the $w->ttkPanedwindow() and $w->ttkStyleConfigure() methods should eliminate the need for Tcl syntax. Since Tcl::pTk does not include complete Perl/Tk-like syntax documentation for Ttk widgets, I suggest looking through upstream Tcl/Tk documentation and Tcl::pTk::Tile POD, and then Tcl::pTk's Ttk widget demos (e.g. ttkpane.pl) to see how it comes together.

Re^2: Controlling resize of Tk::Panedwindow (IDELayout IDEpanedwindow)
by hv (Parson) on Mar 05, 2021 at 15:20 UTC

    Thank you very much for this; I've had a play with the IDEpanedwindow approach, and I agree it is quite funky - I had really hoped to be able to set expandfactors to [1, 0] and get (in effect) an inverted Panedwindow, in which the right/bottom pane would preserve its size under resizing, but the behaviour seems determinedly inconsistent when using those values.

    I'll have at least a quick go at seeing if I can understand why that is before trying Tcl::pTk; I'm slightly reluctant to move wholesale to the latter unless the consensus is that it actually obsoletes Tk.