Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

Auto-scrolling scrollbars with Perl Tk

by Ovid (Cardinal)
on Jul 01, 2002 at 19:12 UTC ( #178646=perlquestion: print w/ replies, xml ) Need Help??
Ovid has asked for the wisdom of the Perl Monks concerning the following question:

I have some "Text" widgets that are created with Tk. I've figured out how to add scrollbars, but it the data printed to the text area goes off the bottom of the text area, the user must grab the scrollbar (or click the down arrow or the trough) to see the new data. What I would like to do is have the Text widget automatically scroll down as new data is added. Here's how I create the Text widget with a scrollbar.

$txtSummary = $root->Scrolled( 'Text', -background => 'blue', -foreground => 'white', -height => '1', -takefocus => '0', -width => '40', -scrollbars => 'oe' )->pack;

That works fine, but this is what I thought was necessary to get the Text widget to "auto" scroll:

$txtSummary->Subwidget( 'yscrollbar' )->configure( -command => [ 'yview' => $txtSummary ] );

That has no apparent affect. Further, the user must move their mouse over the scrollbar to even have the scrollbar's length be correct. In other words, as soon as enough text shows up to mandate a scrollbar, the scrollbar appears, but the bar is the full height of the text area. Only when you do a mouseover does the scrollbar shrink to its correct size.

Hope this made sense :)

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Comment on Auto-scrolling scrollbars with Perl Tk
Select or Download Code
Re: Auto-scrolling scrollbars with Perl Tk
by dree (Monsignor) on Jul 01, 2002 at 19:40 UTC
    You can use:
    $text->see(index)
    From the docs:

    Adjusts the view in the window so that the character given by index is completely visible. If index is already visible then the command does nothing. If index is a short distance out of view, the command adjusts the view just enough to make index visible at the edge of the window. If index is far out of view, then the command centers index in the window.

    UPDATE: you can also see:

    $text->yview(moveto => fraction)
    $text->yview(scroll => number, what)

      Thank you. After I write to the text widget, I then call $txtSummary->see('end'); and it works perfectly.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://178646]
Approved by JayBonci
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-04-23 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (551 votes), past polls