Preface of Ruby/GTK2 Tutorial
|
|
|
|
| Articles Reviews Ruby | |||||||||
| Written by http://www.namaraii.com/hiki/ | |||||||||
| Monday, 21 January 2008 | |||||||||
Page 1 of 7
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:
Save this program in a file named base.rb, and call it with: 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: The third line uses Gtk::Window.new to create a new GTK window with default parameters, as follows:
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 ) | |||||||||
| Next > |
|---|







