in reply to Re^2: Perl Tk Panedwindow Pane Width Sash Position
in thread Perl Tk Scrolled Width Question

Huh?

If you want to hide the scrollbar, just forget it :D

I linked to examples how

Also, use Tk::WidgetDump to see the wealth of information tk provides you ... stuff like widths and heights and stuff

  • Comment on Re^3: Perl Tk Panedwindow Pane Width Sash Position

Replies are listed 'Best First'.
Re^4: Perl Tk Panedwindow Pane Width Sash Position
by buzzthebuzzsaw (Acolyte) on Nov 13, 2015 at 17:40 UTC

    I don't want to specifically hide the scrollbar, it should be there when needed, but I'd like the sash to be moved across automatically when the fields are added so the scrollbar is not shown unless it's needed.

    Regardless I've managed to get it working with the help of Tk::WidgetDump, which is brilliant!

    Here's the updated example above which works, just stretch the width of the window after it opens and then click the button.

    use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new; my($create_fields_num)=5; my($paned_win) = $mw->Panedwindow(-showhandle => 1); $paned_win->pack(-side => 'top', -expand => 1, -fill => 'both'); my($l_pane) = $paned_win->Scrolled('Pane', -scrollbars => 'osoe', -sticky => 'new' )->pack(-side => 'top', -anchor => 'nw', -expand => 1, -fill => 'both' +); my($lab_entry) = $l_pane->LabEntry( -label => "Enter Num:", -labelPack => [-side => 'left', -anchor => 'w'], -textvariable => \$create_fields_num )->pack(-side => 'top', -anchor => 'n', -fill => 'x'); $l_pane->Button( -text => 'Create Fields', -command => [\&create_fields, $l_pane, $paned_win, \$create_fields +_num] )->pack(-side => 'top', -anchor => 'n', -fill => 'x'); my($r_pane) = $paned_win->Scrolled('Pane', -scrollbars => 'osoe', -sticky => 'new' )->pack(-side => 'top', -anchor => 'nw', -expand => 1, -fill => 'both' +); $paned_win->add($l_pane, $r_pane); MainLoop; sub create_fields{ my($l_pane, $paned_win, $fields) = @_; my($sub_frame) = $l_pane->Frame; foreach(@{$sub_frame->configure}){ print join(" ", @{$_}, "\n"); } for(my $field_num=0; $field_num < $$fields; $field_num++){ $l_pane->Entry()->pack(-side => 'left'); } # Move the sash to accommodate the new fields $mw->after(30, sub{ my($xscrollbar, $yscrollbar, $bar_width, $bar_visible); foreach(@{$l_pane->children()}){ if($_->name eq 'scrollbar'){ $xscrollbar = $_; } if($_->name eq 'ysbslice'){ $yscrollbar = $_; } } if($xscrollbar->ismapped){ my($bar_width) = $xscrollbar->width; my($xscrollbar_height)= $xscrollbar->height; my($yscrollbar_width) = $yscrollbar->width; my(undef, $visible_fraction) = $l_pane->xview; my($x, $y) = $paned_win->sash(coord => 0); my($width) = ($bar_width/$visible_fraction)+$xscrollbar_h +eight; if($yscrollbar->ismapped){ $width = $width+$yscrollbar_width; } if($xscrollbar->ismapped){ $paned_win->sash( place => 0, $width , $y); } } }); }

    I couldn't figure out how to get it to get the measurements after the pack so I've simply got them after a delay.

    If there are any recommendations on doing this better I'd be delighted to see them as this seems like overkill!

    Thanks for the help!