tags:

views:

99

answers:

1

I use the following code for printing the line number in a Text widget:

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

The above code is printing the line number and character number okay, but when used in Scrolled widget the output is not printing. What is the problem in the following code? How can I solve this?

$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();
+3  A: 

The Scrolled megawidget automatically creates the scrollbar bindings. It's setting the -xscrollcommand and -yscrollcommand bindings, which overrides the ones you specify when you create the widget. If you want to [ab]use the scroll commands to output line/column numbers, you'll have to forgo using Scrolled and create the scrollbars and bindings yourself.

Michael Carman