Version 6 of checkbutton

Updated 2004-05-22 19:39:17

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


[email protected] wrote in the comp.lang.tcl newsgroup: I would like to be able to control the location of the box in checkbutton and make it appear to the right of it's text (rather than to the left -- as is the default). Is this possible?

You can approximate it with a little wrapper that places a label left of a text-less checkbutton. Quick shot:

 proc lcheckbutton {w args} {
    array set opt {-text ""}
    array set opt $args
    frame $w -bg red
    label $w.1 -text $opt(-text)
    unset opt(-text)
    eval [list checkbutton $w.2 -text {}] [array get opt]
    pack $w.2 $w.1 -side right -fill x
    set w
 } ;# RS
 #--------------------------------------- testing:
 checkbutton .1 -text Right
 lcheckbutton .2 -text Left
 eval pack [winfo children .] -anchor w

To fully emulate the checkbutton protocol, some more work is of course needed...


Instead of work, here's more play: the vertical command places the text of a radio- or checkbutton below the clickable field:

 proc vertical {type w args} {
    frame $w
    set pos [lsearch $args -text]
    if {$pos == -1} {
 set text ""
    } else {
 set text [lindex $args [expr $pos+1]]
 set args [lreplace $args $pos [incr pos]]
    }
    eval $type $w.r $args [list -text ""] -pady 0
    label $w.t -text $text -pady 0
    pack $w.r $w.t -side top -pady 0 -padx 0 -fill x -anchor e
    set w
 } ;# RS

 vertical radiobutton .io.ri$i -text "X$i" -variable Xary($i)

See also

  • Lightbutton a pure Tcl package mimicking the radio and the checkbuttons, with bright and pretty colors.

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