我找到了一个关于如何在textview中插入文本的教程,但我不知道如何在textview中获取文本我阅读Gtk2::TextBuffer Gtk2::TextView Gtk2::TextIter
的文档但我无法获得它就是我的示例代码
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
my $window=Gtk2::Window->new;
$window->signal_connect('delete_event',sub{Gtk2::main_quit;});
my $vbox=Gtk2::VBox->new();
my $textview=Gtk2::TextView->new();
my $textbuffer=$textview->get_buffer;
my $textiter1=$textbuffer->get_end_iter;
my $textiter=$textbuffer->get_start_iter;
$textbuffer->insert($textiter, "Hello");
$textview->set_buffer($textbuffer);
my $button=Gtk2::Button->new("Submit");
$button->signal_connect(clicked=>sub{
my $rt=$textbuffer->get_text($textiter,$textiter1, 1);
print "$rt\n";
});
$vbox->add($textview);
$vbox->add($button);
$window->add($vbox);
$window->show_all;
Gtk2->main;`
提前感谢。