起床并跑步

# Like any other ruby code, require gtk3 after installing from "gem install gtk3"
require 'gtk3'

# Like in Rails, you import working functions from a higher class, in this case the GTK Window
class RubyApp < Gtk::Window

# Calling the original method from GTK Window and redefining the defaults
    def initialize
        super
        
        # Printing window title
        set_title "Center"

        # Invoking built-in GTK connection and calling destroy to replicate the quit action
        signal_connect "destroy" do 
            Gtk.main_quit 
        end
        
        # Sets the window size 500px wide by 400px tall
        set_default_size 500, 400
        
        # Where the window should be displayed on the screen
        set_window_position Gtk::Window::Position::CENTER
        
        # After initialization, show everything
        show
    end
end

# Call the class, just like any other ruby program
window = RubyApp.new

# GTK method. Runs until destroy is called
Gtk.main

将此文件另存为 new.rb 并从终端 ruby new.rb 运行