Gtk2 - perl 学习记录

HBox和VBox创建时有两个参数:
  new(是否平分每个box, 内部各个Widget之间的距离)
Window设置内部间隔:
  set_border_width($px)
让scroll到最底部:
use Glib qw(FALSE);
use Gtk2 -init;
# create a window with a scrolled text view.
my $window = Gtk2::Window->new;
$window->signal_connect (delete_event => sub {exit});
my $scroll = Gtk2::ScrolledWindow->new;
my $textview = Gtk2::TextView->new;
$scroll->add ($textview);
$window->add ($scroll);
$window->show_all;

my $buffer = $textview->get_buffer;

# create a mark at the end of the buffer, with right gravity,
# so that when you insert text, the mark always stays on
# the right (at the end).
my $end_mark = $buffer->create_mark ('end', $buffer->get_end_iter, FALSE);
# every time we insert text, scroll to that mark.
$buffer->signal_connect (insert_text => sub {
$textview->scroll_to_mark ($end_mark, 0.0, TRUE, 0.0, 1.0);
});

# display the output of some long-running command...
open IN, "sleep 1; ls -l |";
Glib::IO->add_watch (fileno IN, ['in', 'hup'], sub {
my ($fd, $condition) = @_;
if ($condition >= 'in') {
$buffer->insert ($buffer->get_end_iter, scalar );
}
if ($condition >= 'hup') {
close IN;
return FALSE;
}
return TRUE;
});

Gtk2->main;
LINK:http://gtk2-perl.sourceforge.net/faq/#46


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值