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"; }

In reply to Re: [PERL Tk] printing Line number in Text widget. by thundergnat
in thread [PERL Tk] printing Line number in Text widget. by ungalnanban

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.