Printing line number in text widget

I am using the following code to print 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 prints line number and character number ok, but when used in widget scrolling, the output doesn't print. 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();

      

+2


a source to share


1 answer


Scrolled

megawidget automatically creates scrollbar bindings. It sets up -xscrollcommand

and bindings -yscrollcommand

that override the ones you specify when creating the widget. If you want to [ab] use scroll commands to display rows / columns, you will have to give up Scrolled

and create scrollbars and anchor bars yourself.



+3


a source







All Articles