Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: [PERL Tk] printing Line number in Text widget.

by thundergnat (Deacon)
on May 10, 2010 at 17:08 UTC ( [id://839262]=note: print w/replies, xml ) Need Help??


in reply to [PERL Tk] printing Line number in Text widget.

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://839262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found