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?
In reply to Re: cursor position in text widget and linenumbertext
by liverpole
in thread cursor position in text widget and linenumbertext
by balee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |