Version 13 of labelframe

Updated 2007-09-24 16:28:54 by LV

Tk 8.4 includes a labelframe. (This was added at 8.4a4(?).) http://purl.org/tcl/home/man/tcl8.4/TkCmd/labelframe.htm

Ttk, added in Tk 8.5, includes a themed labelframe: http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_labelframe.htm .


KPV 2003-07-24 -- For those who don't have 8.4, here's a very basic way of creating one. It only handles a few of the available options--the text always goes in the top left--but it's a good place to start. Two oddities that you should be aware of. First, the label cannot be a child of the frame, otherwise the text gets clipped. Second, the label needs some spacing inside the frame to avoid overlap. Here I did it by gridding in an empty frame, but this means that this widget can only be gridded in. There are other, probably better, ways of making this space but this works.

 proc xlabelframe {w args} {
    set fargs {}                                ;# Options for the frame
    set largs {}                                ;# Options for the label
    foreach {opt val} $args {
        if {$opt == "-text" || $opt == "-font" } {
            lappend largs $opt $val
        } else {
            lappend fargs $opt $val
        }
    }
    set w2 "${w}_label"            ;# CAN'T BE CHILD OF $w!!!
    eval frame $w -bd 2 -relief groove $fargs
    eval label $w2 $largs
    place $w2 -in $w -rely 0 -relx .05 -anchor w
    frame $w._spacer -height 10
    grid $w._spacer -row 0        ;# To avoid title overlap
    return $w
 }

Category Widget - Category Command - Tk syntax help - Arts and Crafts of Tcl-Tk Programming