in reply to Onchange-like event handler for Tk text widget

Update: Please ignore - <<Modified>> works as advertised...

There seems to be a bug on Win32 which keeps <<Modified>> from being generated in case of a Ctrl-V paste. Here is another way to trigger on modifications:

use warnings; use strict; use Tk; my $mw = tkinit; $mw->Text; my $insert = \&Tk::Text::insert; *Tk::Text::insert = sub{changed($_[0]); $insert->(@_); }; my $t = $mw->Text->pack; #$t->bind('<<Modified>>',sub{print shift," changed\n"}); MainLoop; sub changed{ print "$_[0] changed\n"; }
Cheers, Christoph

Replies are listed 'Best First'.
Re^2: Onchange-like event handler for Tk text widget
by vkon (Curate) on Apr 12, 2011 at 07:29 UTC
    I do not know what bug you're talking about,
    my code, rewritten adopted to Tk, behaves correctly for win32, including ctrl+v copy-pasting:
    use Tk; my $t=tkinit->Text->pack; $t->bind('<<Modified>>'=>sub { if($t->editModified) {print qq/chg\n/;$t->editModified(0)} }); MainLoop;

      You are right. I possibly did something stupid like trying to paste from an empty clipboard. Thanks for the clarification.

      Cheers, Christoph
      Dear Monks, thanks a lot. I'll try that. Greetings Lodae