Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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 :)


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

Replies are listed 'Best First'.
Re: Auto-scrolling scrollbars with Perl Tk
by dree (Monsignor) on Jul 01, 2002 at 19:40 UTC
    You can use:
    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.


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2020-02-20 07:13 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (86 votes). Check out past polls.