Hi balee,

I don't see in the documentation for Tk::LineNumberText anything about the method index() being available the way it is for Tk::Text.

Having said that, though, it appears (to address your second question first) that you could access the subwidget like this:

use strict; use warnings; use Tk; use Tk::LineNumberText; my $mw = MainWindow->new; my $t = $mw->LineNumberText('Text')->pack(); $t->insert('end', "This is some\n"); $t->insert('end', "normal text\n"); $t->bind('<Button-1>' => [\&updateStatus]); $mw->bind('<question>' => [\&updateStatus]); # Debug section -- shows objects' keys use Data::Dumper; my @tkeys = keys %$t; my $sw = $t->{'SubWidget'}; my @swkeys = keys %$sw; printf "LineNumberText keys .... %s\n", Dumper([@tkeys]); printf "Subwidget keys ......... %s\n", Dumper([@swkeys]); MainLoop(); sub updateStatus { my $text = $sw->{'text'}; # Get Text obj (Not really a good p +ractice!) my $status = $text->index('current'); print "$status\n"; }

Note, however, that the line my $text = $sw->{'text'}; breaks the OO encapsulation; you're not really supposed to be accessing the data from the Tk::LineNumberText object directly (and the interface could change in the future, leaving you out of luck!)

Maybe you could suggest to the author of Tk::LineNumberText to put in a method to access the underlying Text object.

For your first question, I'm not exactly sure what you're asking.  The line $mw->bind('<question>' => [\&updateStatus]); shows how you could bind the question mark "?" to the subroutine, but it sounds like you're asking more about the cursor keys in particular.  Can you be a bit more specific about what you're trying to do?


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: cursor position in text widget and linenumbertext by liverpole
in thread cursor position in text widget and linenumbertext by balee

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.