Hello Anonymous Monk,

you can profit the <<Modified>> virtual event (see it here), for a first-time-only modification, like in,

use strict; use warnings; use Tk; my $mw = new MainWindow; my $text = $mw->Text(qw/-width 40 -height 10/)->pack; my $current_color = "black"; $text->configure(-insertbackground => $current_color); $text->configure(-cursor => "arrow"); my $button = $mw->Button(-text => "Quit", -command => sub { exit })->p +ack; $text->bind('<<Modified>>', sub{warn "text changed\n"} ); MainLoop;

And you c an also play resetting $text->editModified to zero but follow what our wise zentara said about avoinding an infinite loop: Re: Using Tk::Text and '<<Modified>>'

See also Onchange-like event handler for Tk text widget

L*

PS you can have a better control, but still not optimale with:

my $len; .. $text->bind('<<Modified>>', sub{ if ($len != length $text->Contents ){ $len = length $text->Contents; warn "text changed ($len)\n"; $text->editModified(0) } } );

or better (but breaks on backspaces..)

$text->bind('<<Modified>>', sub{ if ($len ne $text->Contents ){ $len = $text->Contents; warn "text changed\n"; $text->editModified(0) } } );

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: read Tk Text Widget when content changes by Discipulus
in thread read Tk Text Widget when content changes by Anonymous Monk

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.