Preface of Ruby/GTK2 Tutorial  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Ruby
Written by http://www.namaraii.com/hiki/   
Monday, 21 January 2008
Article Index
Preface of Ruby/GTK2 Tutorial  Hot
Ruby/GTK2 Hello World
Ruby/GTK2 Hello World (commented)
More on Signals Handlers
Packing Widgets
Packing Demonstration Program
Packing Using Tables


GTK is accessible through several programming languages, such as C++, Guile, Perl,Python, TOM, Ada95, Objective C, Free Pascal, Eiffel, Java, and C#. This document covers Ruby/GTK2, the Ruby binding for the GTK library version 2. The reader should have some Ruby knowledge. It would be better if he/she has some experience on X programming, but this is not required.This document is still under construction. Do not hesitate to send comments or as questions to the mailing list. Any feedback will be greatly appreciated.


Obviously, you need to install Ruby-GNOME2 on you machine. Please consult one of our Install Guide. If you system is not yet covered, just download manually the latest package from SourceForge, decompress the tarballand read the README file for further instructions.To begin our introduction to GTK, we'll start with the simplest program possible. This program will create a 200x200 pixel window and has no way of exiting except to be killed by using the shell:

require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.show
Gtk.main

Save this program in a file named base.rb, and call it with:

ruby base.rb

We will comment now each step of the program.

The first line links the Ruby/GTK2 library in the program.
require 'gtk2'
The second line calls Gtk.init to initialize the Ruby/GTK2 library with current command line parameters:

Gtk.init

The third line uses Gtk::Window.new to create a new GTK window with default parameters, as follows:
  • size: 200x200
  • style: Gtk::Window::TOP_LEVEL
  • title: same as your program name (here: base.rb)
window = Gtk::Window.new


The fourth line calls Gtk::Window#show to display the window we just created:
window.show

The last line enters the GTK main processing loop:

Gtk.main

Gtk.main is another call you will see in every Ruby/GTK2 application. When control reaches this point, GTK will sleep waiting for X events (such as button or key presses), timeouts, or file IO notifications to occur. In our simple example, however, events are ignored.



Last Updated ( Monday, 21 January 2008 )
 
< Prev   Next >