[clue-cert] Ruby-Gtk: Togglebuttons
Dennis J Perkins
dennisjperkins at comcast.net
Sun Nov 4 20:18:05 MST 2007
#! /usr/bin/ruby
# This example shows how to use Gtk's togglebuttons. Unlike a button,
# the togglebutton stays depressed when first pressed. Pressing it
# again resets it. This is useful for things like Gimp's palette, where
# the option remains set until another one is chosen.
# This example lets you choose any combination of the letters A, B, and
# C. Clicking on GO shows the selections.
require "gtk2"
win = Gtk::Window.new "ToggleButton Example"
win.border_width = 10
win.set_default_size 150, 170
# We need a vertical box to store the widgets.
vbox = Gtk::VBox.new
win.add vbox
# We will use a label widget to show the choices.
$status = Gtk::Label.new
vbox.pack_start $status
# Add a separator to improve the appearance. Since we will not
# reference the separator again, we can use HSeparator's constructor as
# the argument to pack_start.
vbox.pack_start(Gtk::HSeparator.new, true, true, 5)
# Add some toggle buttons.
$t1 = Gtk::ToggleButton.new "A"
vbox.pack_start $t1
$t2 = Gtk::ToggleButton.new "B"
vbox.pack_start $t2
$t3 = Gtk::ToggleButton.new "C"
vbox.pack_start $t3
hsep = Gtk::HSeparator.new
vbox.pack_start(hsep, true, true, 5)
b1 = Gtk::Button.new "Go"
# See which selections are active when the GO button is pressed.
b1.signal_connect("clicked") do
text = ""
text += "A" if $t1.active?
text += "B" if $t2.active?
text += "C" if $t3.active?
# Write the result in $status.
$status.text = text
end
vbox.pack_start b1
win.signal_connect("destroy") {
Gtk.main_quit
}
win.show_all
Gtk.main
More information about the clue-cert
mailing list