in reply to Re: cursor position in text widget and linenumbertext
in thread cursor position in text widget and linenumbertext

Thanks for your help!

Now I can see what was the problem with Linenumbertext.

My first problem was that statusupdate happened only in case of clicking in the text with the mousebutton. I also wanted to update status every keystroke... Meanwhile - with a little help - I figured out: $mw->bind('<KeyPress>' => [\&updateStatus]); In case of linenumbertext, it works, but with simple Text, - I don't understand why - it doesn't.
use Tk; use Tk::LineNumberText; $mw = MainWindow->new; $t = $mw->Text()->pack(); #$t = $mw->LineNumberText('Text')->pack(); $t->insert('end', "This is some\n"); $t->insert('end', "normal texaaaat\n"); $t->insert('end', "normal textasdfasdf\n"); $t->insert('end', "normal textasdasd\n"); $t->bind('<Button-1>' => [\&updateStatus]); $t->bind('<KeyPress>' => [\&updateStatus]); MainLoop(); sub updateStatus { #my ($line,$col) = split(/\./,$t->{'rtext'}->index('insert')); #$status = "line: $line, col: $col"; $status = $t->index('current'); print "$status\n"; }

Replies are listed 'Best First'.
Re^3: cursor position in text widget and linenumbertext
by lamprecht (Friar) on Sep 15, 2009 at 21:45 UTC
    Hi,

    seems to work with 'insert' :

     perl -MTk -e'$t = tkinit->Text->pack;$t->bind("<KeyPress>", sub{print $t->index("insert"),"\n"});MainLoop'
    Cheers, Christoph