Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

[PERL Tk] printing Line number in Text widget.

by ungalnanban (Pilgrim)
on May 10, 2010 at 11:45 UTC ( #839204=perlquestion: print w/ replies, xml ) Need Help??
ungalnanban has asked for the wisdom of the Perl Monks concerning the following question:

I use the following code for printing the line number in 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 vis +it -highlightbackground => 'red' , ### default b +efore 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 no is ok. but I used in Scrolled widget that 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, -xscrollcommand => sub { print"CHAT NO :",$c++; }, # Determines the callback used when the Text widget is scrolle +d horizontally. -yscrollcommand => sub { print"LINR NO :",$r++; }, # Determines the callback used when the Text widget is scrolle +d vertically. )->pack();

Comment on [PERL Tk] printing Line number in Text widget.
Select or Download Code
Re: [PERL Tk] printing Line number in Text widget.
by choroba (Abbot) on May 10, 2010 at 13:35 UTC
    The code is not printing the character and line number even for the non-Scrolled Text widget. Try scrolling down and up again - the numbers never decrease. The Scrolled object is used mainly to avoid the struggle with [xy]scrollcommand - have you read the documentation of scrollcommands in Tk::options? You can create separate Scrollbar objects and define your scrolling methods if it is really what you need.
Re: [PERL Tk] printing Line number in Text widget.
by Anonymous Monk on May 10, 2010 at 13:40 UTC
    From 'perldoc Tk::Scrolled', it seems that the Scrolled widget doesn't support neither -xscrollcommand nor -yscrollcommand



    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: [PERL Tk] printing Line number in Text widget.
by thundergnat (Deacon) on May 10, 2010 at 17:08 UTC

    I'm not really positive what you are trying to accomplish. If you just want visible line numbers at the start of each line, try the Tk::LineNumberText module, I've used it several times and it works nicely.

    If you just want to know the current line and column, you can do something simple like this:

    Update: Made text Scrolled.

    use warnings; use strict; use Tk; my $mw = MainWindow->new; my $index = 'Line: 1 - Column: 0'; my $txt = $mw->Scrolled('Text', -scrollbars => 'se', -wrap => 'none', -background => 'white', -width => 40, -height => 30, -selectbackground => 'skyblue', -insertwidth => 5, -borderwidth => 3, -highlightcolor => 'blue', ### after visit -highlightbackground => 'red', ### default before visit -padx => 5, -pady => 5, )->pack(); my $label = $mw->Label( -textvariable => \$index )->pack(); $txt->bind( '<Key>', \&update_index ); MainLoop; sub update_index { my ( $line, $column ) = split( /\./, $txt->index('insert') ); $index = "Line: $line - Column: $column"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://839204]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-18 03:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (107 votes), past polls