Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Scrolled Tree scrollbar xview problem

by Anonymous Monk
on Mar 17, 2017 at 19:11 UTC ( #1185075=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Ok. I have searched for the last couple hours and cannot find a solution to this problem:

I have a TK Scrolled Tree with, well, scrollbars. It is created thusly ...

$TK{'perltree'}=$TK{'vl'}->Scrolled('Tree', -separator => ':', -background => $COLOR{'white +'}, -font => $FONT{'SAP8BO +LD'}, -exportselection => 1, -selectmode => 'single', -scrollbars => 'ose', -selectforeground => $COLOR{'limeg +reen'}, -selectbackground => $COLOR{'grey' +}, -browsecmd => \&perlTreeSel +ection, -width => 20)->pack(-fi +ll => 'both', -an +chor => 'n', -ex +pand => 1);

Later ... after I populate the tree I want to set the x scrollbar to 75% of it's viewable region and have tried many variations but can't get it to work.

I have tried Subwidget and xview and xviewMoveto all to no success

# Set scroll to 32 $TK{'perltree'}->xview(32); # Focus on the perltree $TK{'perltree'}->update;
Nick? Gabor? Japh? Anyone!

A grateful nzsvz9

Replies are listed 'Best First'.
Re: Scrolled Tree scrollbar xview problem
by zentara (Archbishop) on Mar 17, 2017 at 21:10 UTC
    Hi, without seeing your full working example I couldn't answer to your specific code, but here is a working example to show you a trick with a Scrolled Tree. Notice that scrolling will not work until the mainloop starts and the widget is visible. The work-around is to use an $widget->update. Also notice that the setting range is between 0 and 1.I hope it helps.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Tree; my $mw = MainWindow->new; my $tree = $mw->Scrolled('Tree')->pack(qw/-expand 1 -fill both/); foreach(1 .. 100) { $tree->add($_, -text => "Line $_"); } # you must update the tree first # before the yview works $tree->update; $tree->yview( moveto => .5 ); # or it will always work from a widget # command after the gui has visibility $mw->Button( # always works because you have visibility -text => "move it (this works)", -command => sub { $tree->yview( moveto => 1 ); } )->pack; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Scrolled Tree scrollbar xview problem
by nzsvz9 (Initiate) on Mar 17, 2017 at 19:25 UTC

    I finally logged in ... (facepalm) ... in case the question comes up, $TK{'vl'} is a Tk::Frame which is "view left" or 'vl' in the Tk GUI I'm building. Or trying to build. Or failing at. It depends on your point of view, and visual acuity.

    # Create a left hand view frame in the workspace frame - for the tree $TK{'vl'}=$TK{'ws'}->Frame()->pack(-side => 'left', -anchor => 'n', -expand => 0, -fill => 'both');

    Similarly 'ws' is a workspace Tk::Frame inside the main window. But that's probably not important.

    I create a button to report the tree xview value and just was lost even more ...

    my @pos=$TK{'perltree'}->xview(); my $pos=shift(@pos); print 'xview=' . join(",", $pos) . "\n";

    Thanks from nzsvz9

Re: Scrolled Tree scrollbar xview problem
by nzsvz9 (Initiate) on Mar 18, 2017 at 11:38 UTC

    It was the update before the xview that did it!

    Thanks Japh!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1185075]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2017-07-25 02:20 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (363 votes). Check out past polls.