Re: Textview



I didn't manage to find the command to show the whole "test.txt" file in
the textview. Can someone help for this. Thanx :)

I am not sure if I understand what you are looking for !!
But, the following code will display the contents of a text file using the Gtk2::TextView.

Thanks,

_Ofey.

------------------------------------------
use strict;
use warnings;

use Gtk2 -init;

# Copy the entire file into a string (str)
my $str;
open (TEST,"< test.txt") or die "Cannot open test.txt\n";
while(<TEST>) {
        $str .= $_;
}
close TEST;

# Create a textbuffer to contain that string
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text($str);

# Create a textview using that textbuffer
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef , undef );
$scrolledwindow->add($textview);

# And finally add that scrolledwindow to a window
my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->add($scrolledwindow);
$window->set_default_size (500, 400);
$window->show_all;
Gtk2->main;


                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]