我使用以下代码在文本小部件中打印行号:
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();
以上代码正在打印行号和字符号,但在滚动窗口小部件中使用时,输出不会打印。以下代码有什么问题?我该如何解决这个问题?
$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();
答案 0 :(得分:3)
Scrolled
megawidget会自动创建滚动条绑定。它设置了-xscrollcommand
和-yscrollcommand
绑定,它们会覆盖您在创建窗口小部件时指定的绑定。如果你想[ab]使用滚动命令输出行/列号,你将不得不放弃使用Scrolled
并自己创建滚动条和绑定。