http://www.perlmonks.org?node_id=178646

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.