Call subroutine automatically whenever cursor position changes in a Text widget Call subroutine automatically whenever cursor position changes in a Text widget tkinter tkinter

Call subroutine automatically whenever cursor position changes in a Text widget


There isn't a predefined callback for when the location of the insert mark changes (that's the terminology you're looking for) but it is always set via the markSet method. Maybe you can put something in to intercept calls to that method, see if they're being applied to insert, and do your callback? (That's certainly how I'd do it in Tcl/Tk; I don't know how easy it is to intercept methods on the Perl side of things but surely it must be possible?)


This is what https://stackoverflow.com/a/22356444/2335842 is talking about, see http://p3rl.org/perlobj and http://p3rl.org/Tk::Widget and http://p3rl.org/require for details

#!/usr/bin/perl --use strict; use warnings;use Tk;Main( @ARGV );exit( 0 );BEGIN {    package Tk::TText;    $INC{q{Tk/TText.pm}}=__FILE__;    use parent qw[ Tk::Text ];    Tk::Widget->Construct( q{TText} );    sub markSet {        warn qq{@_};        my( $self, @args ) = @_;        $self->SUPER::markSet( @args );    }}sub Main {    my $mw = tkinit();    $mw->TText->pack;    use Tk::WidgetDump; $mw->WidgetDump; ## helps you Tk your Tk    $mw->MainLoop;}__END__Tk::TText=HASH(0x10f7a74) insert @347,218 at - line 13.Tk::TText=HASH(0x10f7a74) anchor insert at - line 13.