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

Hi All,

Hoping this is a quick one, but I've run into a problem with a Scrolled Pane.

The Pane has a number of entry boxes added to it after the window is created which are larger than the pane can contain and so the scroll bars come into play. Ideally the pane should extend to not require the scrollbars unless the user manually reduces it.

I had planned to get the full width of the scrollbar and then make the pane that width, but I can't figure out how to get the information from the scrollbar subwidget from the Scrolled Pane.

Does anyone know how to get the full scrollregion of a scrollbar placed by Scrolled?

Failing that, the full width of a widget where it's scrolled and sections of it aren't viewable?

Thanks for any help anyone has!

BTB.

I've created some code below to demonstrate the problem. When the program is run it creates the two panes, but the left pane has the scrollbar already in place.

Clicking the button adds new widgets to the left pane and this is where I'd like the sash in the middle to be moved to accommodate the new fields.

How do I modify the width of the left pane so there's no scrollbar required unless it's manually modified by the user?

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, \$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, $fields) = @_; for(my $field_num; $field_num < $$fields; $field_num++){ $l_pane->Entry()->pack(-side => 'left'); } }

Replies are listed 'Best First'.
Re: Perl Tk Scrolled Width Question
by kcott (Archbishop) on Nov 11, 2015 at 02:44 UTC

    G'day buzzthebuzzsaw,

    "Ideally the pane should extend to not require the scrollbars unless the user manually reduces it."

    Take a look at the documentation for Tk::Pane. You'll need these options:

    -scrollbars
    Use this to specify the position of scrollbars and whether to display always or only when needed. There's more information on this option in Tk::Scrolled.
    -sticky
    Use this to stretch the widget to the maximum available size.

    See also: Tk::Scrollbar, Tk::Widget and Tk::Wm.

    You may need to do other things (e.g. with geometry management) but, as you've shown no code, I'm unable to say what that might be.

    — Ken

      Both of those options are being used, but do not address the issue I'm seeing.

      I've been looking through the documentation to get some idea of what I need to do, but can't find a way to do it.

      My thinking was to get the full width of the widgets inside the scrolled region and than change the 'sash' in the Panedwindow to accommodate the width, but I can't get that width anywhere. All I've managed to get is the visible width of the widgets, not the width including what's not visible.

Re: Perl Tk Scrolled Width Question
by stevieb (Canon) on Nov 10, 2015 at 22:35 UTC
    Can you supply the code you've got so the Tk monks can see what you've tried and can try to spot where your issue is?

      I've added some code to the question which gives an idea of the problem.

      For some reason the code wasn't being displayed with formatting when I did an update but it appears to be working now.

Re: Perl Tk Scrolled Width Question
by Anonymous Monk on Nov 11, 2015 at 01:12 UTC
Re: Perl Tk Panedwindow Pane Width Sash Position
by Anonymous Monk on Nov 12, 2015 at 03:12 UTC

      Thanks for that, ultimately that's what I'll do, but I can't find a way to get the actual width required to hide the scrollbar.

      Either I need to get the width of the Pane including the area that's not visible, or I need to get the information from the scrollbar.

      But I've not found a way of doing that yet.

        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