开发者

How can I scroll a single frame in Perl Tk?

开发者 https://www.devze.com 2022-12-20 13:47 出处:网络
I\'m trying to create a GUI for a conversion program. I want to create a frame containing the log file, but I can\'t get it. I found some codes to make the entire window scrollable, but it\'s not what

I'm trying to create a GUI for a conversion program. I want to create a frame containing the log file, but I can't get it. I found some codes to make the entire window scrollable, but it's not what I want. I just want to scroll a frame containing a label with a chainging text-variable.

I've even tried the following code:

 $s = $parent->new_ttk__scrollbar(-orient => 'vertical', -command => [$frame, 'yview']);
 $frame->configure(-scrollcommand => [$s, 'set']);

but I get an error. Perl says that scrollcommand is not a recognised command.

I've posted a piece of my code on pastebin : http://pas开发者_运维问答tebin.com/d22e5b134


Frame widgets aren't scrollable (i.e. they don't support the xview and yview methods). Use a text widget instead of a label in a frame. If you're lazy, use Tkx::Scrolled to do it for you. If you're using a label because you want it to be read-only, use Tkx::ROText instead. And while I'm promoting my own modules, use Tkx::FindBar for a nice Find-As-You-Type search interface.

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消