I need to check the license of this document.
(In any case, reproduction in verbatim is allowed.)
Ruby/Tk Tutorial
HelloWorld SimpleWidgets BindingEvents MoreWidgets Scrollbars Menus MakeItBeautiful MoreInformation
So you found Ruby and liked it. Now you need a GUI toolkit. Be warned: gtk, Qt, fox and wx have Ruby bindings as well. Maybe those suit your needs better.
This tutorial is aimed at people that want to use Tk as toolkit with Ruby. It does not really matter whether you are very proficient in Ruby or with toolkits. Examples may overwhelm the novice sometimes, but each line is explained. Step over it and come back in a later stage. The small differences in those lines provide a wealth of information for the more experienced programmer.
Note: This is a work in progress. You are free to edit this wiki to improve it.
A few reasons to use Tk:
- Tk is supported in many places (though other toolkits are definitely catching up),
- Tk may look small or simple, but is very powerful. Of course it can do all basics, like any toolkit, but some things are done in a very simple way,
- Its canvas has some very nice features for selecting and manipulating objects (like lines and curves) on it. It can even dump its content in a PostScript file.
- Tk has a few prebuilt windows like a color chooser and dialog,
- Can use many Tk extensions from Ruby.
A few reasons not to use Tk
- In a certain environments, other toolkits will look better (Gtk in Gnome, Qt under KDE, Fox; wxWidgets uses native widgets),
- You are addicted to an IDE and demand you can build your UI with mouseclicks (or may be that's actually a reason to look at the building blocks and read on :-)
Installation Problems
If you installed Ruby yourself, possibly the Tk bindings do not work. First, make sure you have Tcl/Tk installed. Then look at a configuration fix.
The Course
- HelloWorld How to start Tk from Ruby and the first little program,
- SimpleWidgets, building a small GUI,
- BindingEvents, reacting on user input,
- MoreWidgets, building a GUI with well-behaving layout,
- Scrollbars,
- Menus, in its many appearances,
- MakeItBeautiful, step beyond the defaul Tk looks,
- MoreInformation, Places where you want to look, too; before, during and after this course.