框架小部件不可滚动(即它们不支持xview
andyview
方法)。在框架中使用文本小部件而不是标签。如果您很懒惰,请使用Tkx::Scrolled为您完成。如果您使用标签是因为您希望它是只读的,请改用Tkx::ROText。当我在推广我自己的模块时,使用Tkx::FindBar获得一个漂亮的 Find-As-You-Type 搜索界面。
use strict;
use warnings;
use Tkx;
use Tkx::FindBar;
use Tkx::ROText;
use Tkx::Scrolled;
my $mw = Tkx::widget->new('.');
my $text = $mw->new_tkx_Scrolled('tkx_ROText',
-scrollbars => 'osoe',
-wrap => 'none',
);
my $findbar = $mw->new_tkx_FindBar(-textwidget => $text);
$findbar->add_bindings($mw,
'<Control-f>' => 'show',
'<Escape>' => 'hide',
'<F3>' => 'next',
'<Control-F3>' => 'previous',
);
$text->g_pack(-fill => 'both', -expand => 1);
$findbar->g_pack(
-after => $text,
-side => 'bottom',
-fill => 'x',
);
$findbar->hide();
open(my $fh, '<', __FILE__) or die;
$text->insert('end', do { local $/; <$fh> });
close $fh;
$mw->g_focus();
Tkx::MainLoop();