如何在Perl / Gtk2 TextView中获取文本

时间:2015-01-11 01:42:17

标签: perl user-interface

我找到了一个关于如何在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;`

提前感谢。

0 个答案:

没有答案