首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >perltk:突出显示文本字段中的文本并更新标签

perltk:突出显示文本字段中的文本并更新标签
EN

Stack Overflow用户
提问于 2012-03-02 15:12:04
回答 2查看 377关注 0票数 1

在Windows XP上使用TK。

代码语言:javascript
复制
my $mw = new MainWindow;
my $text1 = $mw->Text(-width=>20, -height=>10)
            ->place(-x=>350, -y=>460); 

my $showlabel = $mw->Label(-text => "nothing selected")
            ->place(-x=>50, -y=>120);

$text1->configure( -command => sub { 
    $showlabel->configure(-text => "You selected:\t" . 
                          $text1->getSelected() 
                         )
  } 
);

运行代码后,每当我突出显示任何文本时,$showlabel都不会更新。有人能帮帮忙吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-02 18:00:09

编辑:没有按钮的代码。

别忘了在程序结束时调用MainLoop来显示窗口。没有它,什么都不会发生。

试试这个:

代码语言:javascript
复制
use strict;
use warnings;

use Tk;

my $mw = new MainWindow;
my $text1 = $mw->Text(-width => 20, -height => 10)
                   ->place(-x => 350, -y => 460);
my $showlabel = $mw->Label(-text => "nothing selectd")
                       ->place(-x => 50, -y => 120);
$text1->bind('<KeyPress>'     , \&sel);
$text1->bind('<ButtonPress>'  , \&sel);
$text1->bind('<ButtonRelease>', \&sel);

MainLoop;

sub sel
{
    $showlabel->configure(-text => "You selected:\t" . $text1->getSelected);
}
票数 2
EN

Stack Overflow用户

发布于 2012-03-03 23:43:31

使用以下命令:

代码语言:javascript
复制
$text1->bind( '<<Selection>>', sub {
  $showlabel->configure(-text => "You selected:\t".$text1->getSelected() )
} );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9529400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档