radiobutton
Tcl/Tk
#!/usr/local/bin/wish4.2
proc print_v {} {
global v
puts $v
}
radiobutton .top -text top -anchor w -variable v -value top
radiobutton .middle -text middle -anchor w -variable v -value middle
radiobutton .bottom -text bottom -anchor w -variable v -value 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
print $v, "\n"
end
$v = TkVariable.new
TkRadioButton.new {
text 'top'
variable $v
value 'top'
anchor 'w'
pack('side' => 'top', 'fill' => 'x')
}
TkRadioButton.new {
text 'middle'
variable $v
value 'middle'
anchor 'w'
pack('side' => 'top', 'fill' => 'x')
}
TkRadioButton.new {
text 'bottom'
variable $v
value 'bottom'
anchor 'w'
pack('side' => 'top', 'fill' => 'x')
}
TkButton.new {
text 'Quit'
command 'exit'
pack
}
Tk.root.bind "1", proc{print_v}
Tk.mainloop