proc find {w what tag _status} {
upvar #0 $_status status
foreach {from to} [$w tag ranges $tag] {
$w tag remove $tag $from $to
}
set pos [$w search -count n -- $what insert+2c]
if {$pos eq ""} {
set status "not found: $what"
} else {
set status "found at $pos: $what"
$w mark set insert $pos
$w see $pos
$w tag add $tag $pos $pos+${n}c
}
}# Demo with an entry for the search term, a text, and a label for the status string: package require Tk
pack [entry .e -textvariable Find] -fill x
bind .e <Return> {find .t $Find hilite state}
pack [text .t -wrap word]
.t tag configure hilite -background orange
pack [label .l -textvariable state] -anchor wSee also Simple search and replaceSee also Incremental GUI text search