Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perl Tk Panedwindow Pane Width Sash Position

by Anonymous Monk
on Nov 12, 2015 at 03:12 UTC ( [id://1147529]=note: print w/replies, xml ) Need Help??


in reply to Perl Tk Scrolled Width Question

See Tk::Panedwindow/http://www.tcl.tk/man/tcl8.5/TkCmd/panedwindow.htm#M17

In sub create_fields add

{ my($x,$y) = $paned_win->sash( coord => 0) ; $paned_win->sash( place => 0, $x + 400, $y ); }

That will grow the left pane ; adjust this code as you require.

Replies are listed 'Best First'.
Re^2: Perl Tk Panedwindow Pane Width Sash Position
by buzzthebuzzsaw (Acolyte) on Nov 12, 2015 at 13:50 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

        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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147529]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-23 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found