ysitbook 发表于 2011-03-14 13:48

Ruby 继承 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
页: [1]
查看完整版本: Ruby 继承 Gtk::Window