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!


In reply to Re^4: Perl Tk Panedwindow Pane Width Sash Position by buzzthebuzzsaw
in thread Perl Tk Scrolled Width Question by buzzthebuzzsaw

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.