in reply to How can I get indefinite scroll to work in a TK text widget

Bad title. Bad title!

That said - It Works For Me TM.

use Tk; $bottomFrame = MainWindow->new(); sub display_text { my $txt_summary = $bottomFrame->Scrolled( "Text", -background => 'blue', -foreground => 'white', -height => '1', -takefocus => '0', -width => '40', -scrollbars => 'oe', )->pack(qw(-fill both -ex +pand 1)); open(FH, "cuentos.txt") || die "no Abrio nada"; while (<FH>) { $txt_summary -> Insert($_); } close (FH); $txt_summary->see('end'); return $txt_summary; } display_text(); MainLoop; __END__

Maybe it's context? is it the missing arguments to pack()? what kind of object is $bottomFrame actually? Also, "text" ought to be "Text".

thanks to roboticus for the inspired title

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: How can I get indefinite scroll to work in a TK text widget
by padawan_linuxero (Scribe) on May 16, 2008 at 17:31 UTC
    Hi!
    my $bottomlowframe = $mw->Frame()->pack(-fill=>'x');
    it just a Frame
    but I think I ask the wrong question and I am sorry:(
    I want that the Text widget continue to scroll the text "undefinitly" or "forever" but at a reasonable speed to be able to read it, I hope it makes more sense. you know like those things that keep showing the news on the tv but I want it in my Tk windows
    Thank you

      Ah. Makes more sense. While perl is busy executing display_text(), the GUI doesn't get updated. You need Tk::after or ::repeat for that:

      use Tk; $bottomFrame = MainWindow->new(); my $txt_summary = $bottomFrame->Scrolled( "Text", -background => 'blue', -foreground => 'white', -height => '1', -takefocus => '0', -width => '40', -scrollbars => 'oe', )->pack(qw(-fill both -ex +pand 1)); open(FH, "cuentos.txt") || die "no Abrio nada"; sub display_text { if(eof(FH)) { $bottomFrame->afterCancel($bottomFrame->{RepeatID}); close (FH); $txt_summary -> Insert("\n== FIN ==",'end'); return; } else { chomp(my $line = <FH>); $txt_summary -> Insert("\n$line",'end'); } $txt_summary->see('end'); } $bottomFrame->{RepeatID} = $bottomFrame->repeat(500, \&display_text); MainLoop; __END__

      But probably you want Tk::fileevent. Note also that "Scrolled" means "attach a scrollbar to it", and not "scroll this widget".

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Hi
        Thank you so much for your help
        I have another question if I want it to continue in a infinite loop, what I need to do?
        put everything in a Sub routine and use something like repeat to make it run again?
        Thanks !!!