package require Itcl
itcl::class sampleconf { ;# a sample class with a single public variable
public variable publicv ;# this var is adjusted using the configure -publicv...
constructor {} { }
method setpublicv {dn} {
set publicv "$dn"
puts $dn
}
method shwopublicv {} {
puts $publicv
}
}
# create a sample instance of the class:
set btn [sampleconf h2]
# directory configure in the class
h2 configure -publicv "good"
h2 shwopublicv
# add a widiget configure for a variable
# add a configbody for public variable publicv
itcl::configbody sampleconf::publicv {tk_messageBox -message "Publicv in $this was set to $publicv by a configure command."}
h2 configure -publicv "A new Value"
# change the publicv by configure and you see a message box.
h2 configure -publicv "The same old Value"
h2 setpublicv "A value which is not sent via the configbody"
# change the publicv again by configure and again you see a message box.
h2 configure -publicv "Another Value"