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++;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.