A simple efficient way to scroll alot of text, like for a teleprompter. It scrolls fast for demo, just slow it down. It also only handles plain text, trying to display html or code, will interfere with the markup process.
#!/usr/bin/perl use warnings; use strict; use Gtk2 '-init'; use Gnome2::Canvas; use constant TRUE=>1; use constant FALSE=>0; my $ts ; if($ARGV[0]){ open (FH,"< $ARGV[0]"); read( FH, $ts, -s FH ); close FH; }else{ while(<DATA>){ $ts .= $_ } } $ts =~ tr[\x0a\x0d][ ]d; #strip newlines my $width = 650; my $height = 60; my $window = Gtk2::Window->new(); my $canvas = Gnome2::Canvas->new_aa(); my $black = Gtk2::Gdk::Color->new (0x0000,0x0000,0x0000); $canvas->modify_bg('normal',$black); $window->add($canvas); $window->signal_connect('destroy'=>\&_closeapp); $window->set_default_size($width,$height); my $root = $canvas->root; my $markup = "<span foreground= '#00FF00' size='50000' weight = 'ultralight'><i><u> $ts </u></i></span>"; my $text = Gnome2::Canvas::Item->new($root, 'Gnome2::Canvas::Text', #text => $markup, markup => $markup, fill_color => 'green', anchor => 'w', justification => 'left', x=>0, x_offset=> -$width/3, y=>30); $text->raise_to_top(); $window->show_all(); my $timer = Glib::Timeout->add(1000/24, \&timer); my ($x1, $y1, $x2, $y2) = $text->get_bounds; print "$x2\n"; my $right_bound = $x2 + $width; Gtk2->main(); sub timer { $text->move( -20, 0 ); my ($x1, $y1, $x2, $y2) = $text->get_bounds; print "$x2\n"; if($x2 < -40){ $text->move( $right_bound + 60, 0 ); } return 1; } sub _closeapp{ Gtk2->main_quit(); return 0; } __DATA__ This article is Copyright 1990-2004 by Steve Summit. Content from the book _C Programming FAQs: Frequently Asked Questions_ is made availabl +e here by permission of the author and the publisher as a service to the community. It is intended to complement the use of the published text and is protected by international copyright laws. The on-line content may be accessed freely for personal use but may not be republished without permission. __END__

In reply to Gtk2 Scrolling Text by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.