[clue-tech] First example Ruby Gtk program
Dennis J Perkins
dennisjperkins at comcast.net
Thu Oct 25 22:16:33 MDT 2007
#! /usr/bin/env ruby
# Display the canonical "hello world" message of a first
# program in a new programming language.
# Note that this program has a flaw that manifests itself
# when shutting down. Clicking on the close button makes
# the window disappear, but the event loop is still running.
# This solution to this issue will be shown in another example
# program.
# Use Ruby's gtk2 library.
require "gtk2"
# Initialize Gtk.
Gtk.init
# Create the toplevel window,
win = Gtk::Window.new
# Add a title to the program.
win.set_title "Hello World"
# Add a 10-pixel border to the edge of the toplevel window canvas.
win.border_width = 10
# Create a label to display our "Hello world" message.
label = Gtk::Label.new "Hello world"
# Add our newly created label to the toplevel window.
win.add label
# Widgets are not automatically visible, so make them visible now.
# The toplevel window should be made visible last to avoid seeing
# widgets and the toplevel window change size as the packing manager
# change size as the packing manager figures out the appropriate sizes
# for everything.
label.show
win.show
# Start the event loop.
Gtk.main
More information about the clue-tech
mailing list