Version 9 of checkbutton

Updated 2005-11-17 19:17:23 by willdye

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

The older (8.4) man page is at: http://purl.org/tcl/home/man/tcl8.4/TkCmd/checkbutton.htm


Note the 8.5 checkbutton includes the new "tristate" options, implemented at the behest of Tip #110 http://www.tcl.tk/cgi-bin/tct/tip/110


[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)

Here's a procedure which does all the nessecary stuff to bind label and checkbutton - when label is of left as separate control and checkbox is textless. All mouse interactions are taken care of - on_mouseover, etc:

   proc setWidgetsState { state widgets } {
        foreach widg $widgets { $widg configure -state $state }
   } ; # SetWidgetsState

   proc bindLabelToCheckbutton { lbl chkBtn } {
        foreach prop {-activebackground -activeforeground} {
             $lbl configure $prop [$chkBtn cget $prop]
         }

        bind $lbl <Enter> [list setWidgetsState active [list $lbl $chkBtn]]
        bind $lbl <Leave> [list setWidgetsState normal [list $lbl $chkBtn]]

         bind $chkBtn <Enter> +[list setWidgetsState active $lbl]
         bind $chkBtn <Leave> +[list setWidgetsState normal $lbl]

        bind $lbl <1> [list $chkBtn invoke]
  } ; #bindLabelToCheckbutton

Just add the following call to /lcheckbutton/ (above) and you are all done:

   bindLabelToCheckbutton $w.1 $w.2

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