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 maintain read-only sections of a text widget?
 If you want the entire text widget to be read-only, set the "-state"
option of the `text` widget to "disabled".  To create read-only sections
in a text widget, you should make use of the `text` widget tag facility.
 The following is a minimal example of this:

pack [text .text]
.text tag configure readonly -background yellow
rename .text ..text
proc .text args {
    if {[string match ins* $args] &&
	[lsearch -exact [.text tag names [lindex $args 1]] readonly]>-1} return
    if {[string match del* $args]} {
	if {[string compare {} [lindex $args 2]]} {
	    if {[string compare {} [eval .text tag nextrange  readonly [lrange $args 1 2]]]} return
	} else {
	    if {[lsearch -exact [.text tag names  [lindex $args 1]] readonly]>-1} return
    uplevel ..text $args