Version 8 of label

Updated 2001-12-21 12:41:37

label - create and manipulate label (text or image) widgets

http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/label.htm


Composite labels: A text label can hold either a constant text or a reference to a textvariable from which it is updated. Occasionally one wants both mixed, for instance to display "Distance from $from to $to: $mi miles", and auto-updated when one of those variables changes. The following code can help:

 proc compositelabel {w contents} {
    frame $w
    set n 0
    foreach i $contents {
        set w1 [label $w.[incr n]]
        if [regexp {^[$](.+)} $i -> varname] {
            $w1 configure -textvar ::$varname
        } else {
            $w1 configure -text $i
        }
    }
    eval pack [winfo children $w] -side left
 }
 # usage example:
 compositelabel .dist {Distance from $from to $to is $m miles}

Make sure that the second argument is braced - the dollar signs are not to be seen by the Tcl parser, but rather used to indicate the following is the name of a global variable, not a text constant... (RS)


Tk syntax help - Arts and crafts of Tcl-Tk programming - Category Command