Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am working on Perl/Tk. I have a small query about Scrollbar's in Perl/Tk. In a small program i have a button, ROText box and a Scrollbar. I am trying to implement the autoscroll functionality i.e when i click on the button the message should display in the Textbox, and the new text that is displayed should be visible. The previous text should scroll up and the current text that is inserted in the text box should be visible automatically. But i am not getting it to work. I need to scroll down to see the new text. Here is the code that i am working with.
use Tk; use strict; require Tk::ROText; my $rotext_box; my $frame; my $count=0; my $mw = MainWindow->new; $mw->title("Scrollbar_View"); $mw->geometry("500x300"); $mw->resizable(0,0); my $frame1 = $mw->Frame()->pack(-side => 'top'); my $send_cmd_btn = $frame1->Button(-text => 'Send_Cmd', -state=>'normal', -command =>\&show) ->pack(-side=>'left', -padx=>5); $frame = $mw->Frame(-relief => 'groove', -background=>'white') + ->pack(-side => 'top', -fill=>'x', -fill=>'y' +); my $xscroll = $frame->Scrollbar(-orient => 'horizontal'); my $yscroll = $frame->Scrollbar(); $rotext_box = $frame->ROText(-background =>'white', -height => 25, + -width => 120, -xscrollcommand => ['set' , $xscroll], -yscrollcommand => ['set', $yscroll] ); $xscroll->configure(-command => ['xvi +ew', $rotext_box]); $yscroll->configure(-command => ['yview', $rotext_box]); $xscroll->pack(-side => 'bottom', -fill => 'x'); $yscroll->pack(-side => 'right', -fill => 'y'); $rotext_box->pack(-side => 'bottom', -fill => 'y'); MainLoop(); sub show { Tk::DoOneEvent(0); my $text_to_Insert = "This is a large text that is displayed in th +e ROText for $count time\n\n\n"; $rotext_box -> insert('end', $text_to_Insert); $rotext_box->update(); $count++; }

Replies are listed 'Best First'.
Re: Query about Scrollbar
by ikegami (Patriarch) on Nov 17, 2008 at 05:53 UTC
    Here are two solutions:
    $rotext_box->insert('end', $text_to_Insert); $rotext_box->see('end');
    $rotext_box->PRINT($text_to_Insert);

    The difference is the latter will only move if the end is in view before the text is inserted.

    ->update() isn't necessary in either case.

      Thanks ikegami,
      It worked perfectly.... Thanks a lot :)