【问题标题】:printing Line number in Text widget在文本小部件中打印行号
【发布时间】:2010-05-10 12:18:31
【问题描述】:

我使用以下代码在 Text 小部件中打印行号:

my $c = 0;
my $r = 0;

$txt = $mw->Text(
    -background          => 'white',
    -width               => 400,
    -height              => 300,
    -selectbackground    => 'skyblue',
    -insertwidth         => 5,
    -borderwidth         => 3,
    -highlightcolor      => 'blue',  # after visit
    -highlightbackground => 'red',   # default before visit
    -xscrollcommand      => sub { print "CHAT NO :", $c++; },
    # Determines the callback used when the Text widget is scrolled horizontally.
    -yscrollcommand      => sub { print "LINR NO:", $r++; },
    # Determines the callback used when the Text widget is scrolled vertically.
    -padx                => 5,
    -pady                => 5,
)->pack();

上面的代码可以打印行号和字符号,但是在 Scrolled 小部件中使用时,输出不打印。下面的代码有什么问题?我该如何解决这个问题?

$txt = $mw->Scrolled('Text',
    -scrollbars          => 'se',
    -background          =>'white',
    -width               => 400,
    -height              => 300,
    -insertwidth         => 5,
    -borderwidth         =>3,
    -highlightcolor      => 'blue',  # after visit
    -highlightbackground => 'red' ,  # default before visit
    -padx                => 5,
    -pady                => 5,
    # Determines the callback used when the Text widget is scrolled horizontally. 
    -xscrollcommand      => sub { print"CHAT NO :",$c++; },
    # Determines the callback used when the Text widget is scrolled vertically.
    -yscrollcommand      => sub { print"LINR NO :",$r++; },
)->pack();

【问题讨论】:

    标签: perl tk perltk


    【解决方案1】:

    Scrolled megawidget 自动创建滚动条绑定。它正在设置-xscrollcommand-yscrollcommand 绑定,它会覆盖您在创建小部件时指定的绑定。如果您想 [ab] 使用滚动命令来输出行号/列号,则必须放弃使用 Scrolled 并自己创建滚动条和绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多