Ruby/GUI/gtk
Материал из Wiki.crossplatform.ru
Версия от 18:05, 13 сентября 2010; ViGOur (Обсуждение | вклад)
Ruby/GTK version of "Hello, World":
require "gtk" window = Gtk::Window::new button = Gtk::Button::new("Hello, World!") button.signal_connect(Gtk::Button::SIGNAL_CLICKED) { puts "Goodbye, World!" exit } window.add(button) button.show window.show Gtk::main
Subclass Gtk::Window
require "gtk" class SampleWindow < Gtk::Window def initialize super set_title("Ruby/GTK Sample") signal_connect("destroy") { Gtk::main_quit } entry = Gtk::Entry.new button = Gtk::Button.new("All Caps!") button.signal_connect("clicked") { cmdAllCaps(entry) } box = Gtk::HBox.new box.add(Gtk::Label.new("Text:")) box.add(entry) box.add(button) add(box) show_all end def cmdAllCaps(textField) textField.set_text(textField.get_text.upcase) end end SampleWindow.new Gtk::main