Friday, August 27, 2010

GTK Programming in Ruby (1) - Simple Window

Here is my first GTK program with Ruby.

# window01.rb

require 'gtk2'

class AppWindow < Gtk::Window

  def initialize
    super
    window_settings('Simple Window', 400, 300)
    event_settings
    show
  end
    
  def window_settings(title, width, height)
    set_title title
    set_default_size width, height
    set_window_position Gtk::Window::POS_CENTER
  end

  def event_settings
    signal_connect "destroy" do 
      Gtk.main_quit 
    end    
  end
  
end

Gtk.init
AppWindow.new
Gtk.main

This is how it looks.

No comments:

Post a Comment