Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  How can I check to see if the text widget contents have changed?
 The `text` widget does not have a `-textvariable` option like the
`entry` widget, so you must be more devious in determining when the
contents have changed.

If the contents of the text widget are known to be small, then a simple
solution would be to cache the original contents and use `string compare
$cache [.text get 1.0 end-1c]` to check for changes.

A more general solution that some have recommended is to make bindings
that set a global flag when the text widget is edited.  This is often
imperfect because you have to make sure to account for all bindings
which might edit the widget.  Also, you don`t really want these bindings
to trigger all the time, but rather just once after any save command.
Alternatively, you could place a wrapper proc around the text widget
which intercepts any insert/delete calls:

pack [text .text]
set .text 1; # Represents whether text is SAVED or not
rename .text ..text
proc .text args {
    global .text
    if {[regexp {^(ins|del).*} [lindex $args 0]]} { set .text 0 }
    uplevel ..text $args

The only thing that misses is direct C calls and embedded window
addition.  Don`t forget to `set .text 1` when you save text.