require 'gtk'
def greeting(num)
puts "This is button #{num}"
end
# Build the GUI
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
hbox = Gtk::HBox.new(false,0)
button1 = Gtk::Button.new("button 1")
button2 = Gtk::Button.new("button 2")
hbox.pack_start button1, true, true, 0
hbox.pack_start button2, true, true, 0
window.add hbox
# Callbacks and configuration.
window.set_title "Two buttons"
window.border_width 10
window.signal_connect('delete_event') { false }
window.signal_connect('destroy') { Gtk.main_quit }
button1.signal_connect('clicked') { greeting(1) }
button2.signal_connect('clicked') { greeting(2) }
# All done.
window.show_all
Gtk.main |