< Ruby Programming < GUI Toolkit Modules

Of Ruby GUI bindings, the Tk binding is the oldest; it is widely available and still more or less the default toolkit for GUI programming with Ruby. Nevertheless, currently there exists no comprehensive manual for Ruby/Tk; the Ruby book recommends inferring Ruby/Tk usage from the Perl/Tk documentation.

The current Ruby "PickAxe book" has a chapter on Ruby/Tk.

Documentation

  • Theres a pretty good tutorial www.tutorialspoint.com/ruby/ruby_tk_guide.htm .
  • There are some pleasantly looking tutorials at tkdocs.com (its not really Tks official site).
  • After having introducted yourself to the concepts of Tk you should also be able to read TclTks official reference (this is also available as man pages on Unix or a CHM file on Windows[1]).

You may also be able to comfortably read PerlTks documentation as the Ruby bindings are said to be modeled after Perls.

Look and Feel

The look and feel of your Tk application depends on the version of the Tk library your Ruby interpreter is linked against:

  • Tk 8.4 and below is notorious for its ugly look. The widgets have the outdated Motif look and feel, and, on Unix-based systems[2], bitmap fonts are used.
  • Tk 8.5 and above look more modern. It is shipped with the Tile theming engine[3], and widgets now look native to the hosting platform[4]. On Unix-based systems outline fonts are now used.

Availability

If the Tk toolkit isnt already installed on your system, youll have to install it. You may use your systems package manager for this.

If you built Ruby before having installed the Tk dev package, its likely that it was built without Tk built in. For 1.9 versions you might be able to get away with installing it as a gem but your best bet is to install the tk dev package and reinstall Ruby so that it builds with the Tk bindings.

Windows

By default the old one click installer has the Tk binaries, however youll still need to install the Tk toolkit from ActiveState .

If youre using the new rubyinstaller then for 1.8.6 this might help or for 1.9 this might help

Theres a precompiled gem which should work out-of-the-box: tk-win.
It includes sources and libraries directly from Hidetoshi NAGAI. Its Ruby 1.9 only.

You could also try the ffi-tk gem, or download this for 1.9 mingw users.

The hope is that future versions of rubyinstaller will come with the binaries built in, then the above work-arounds wont be necessary.

Alternatives

A few more gui toolkits are compared here.

notextile.


  1. The ActiveState package for Windows, mentioned above, contains the documentation as a CHM file.
  2. on X-Window systems, to be exact.
  3. The Tile theming engine can be installed on older Tk 8.x libraries as well.
  4. Though you may have to turn on this feature (?).
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.