checkbutton


Tcl/Tk


#!/usr/local/bin/wish4.2

proc print_v {} {
	global v_top v_middle v_bottom
	puts [format "top: %s middle: %s bottom: %s" $v_top $v_middle $v_bottom]
}

checkbutton .top -text top -anchor w -variable v_top
checkbutton .middle -text middle -anchor w -variable v_middle
checkbutton .bottom -text bottom -anchor w -variable v_bottom
pack .top .middle .bottom -side top -fill x

button .b -text Quit -command exit
pack .b

bind all <1> {print_v}

ruby/Tk


#!/usr/local/bin/ruby

require "tk"

def print_v
  printf "top: %s middle: %s bottom %s\n", $v_top.value, $v_middle.value, $v_bottom.value
end

$v_top = TkVariable.new
$v_middle = TkVariable.new
$v_bottom = TkVariable.new

$v_top.value = 0
$v_middle.value = 0
$v_bottom.value = 0

TkCheckButton.new {
  text 'top'
  variable $v_top
  anchor 'w'
  pack('side' => 'top', 'fill' => 'x')
}
TkCheckButton.new {
  text 'middle'
  variable $v_middle
  anchor 'w'
  pack('side' => 'top', 'fill' => 'x')
}
TkCheckButton.new {
  text 'bottom'
  variable $v_bottom
  anchor 'w'
  pack('side' => 'top', 'fill' => 'x')
}

TkButton.new {
  text 'Quit'
  command 'exit'
  pack
}

Tk.root.bind "1", proc{print_v}

Tk.mainloop