Ruby Programming/GUI Toolkit Modules/Tk

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

 * There&rsquo;s a pretty good tutorial www.tutorialspoint.com/ruby/ruby_tk_guide.htm.


 * There are some pleasantly looking tutorials at tkdocs.com (it&rsquo;s not really Tk&rsquo;s official site).


 * After having introducted yourself to the concepts of Tk you should also be able to read TclTk&rsquo;s official reference (this is also available as man pages on Unix or a CHM file on Windows ).

You may also be able to comfortably read PerlTk&rsquo;s documentation as the Ruby bindings are said to be modeled after Perl&rsquo;s.

Look and Feel
The &ldquo;look and feel&rdquo; 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 &ldquo;ugly&rdquo; look. The widgets have the outdated Motif look and feel, and, on Unix-based systems, bitmap fonts are used.


 * Tk 8.5 and above look more modern. It is shipped with the Tile theming engine, and widgets now look native to the hosting platform . On Unix-based systems outline fonts are now used.

Availability
If the Tk toolkit isn&rsquo;t already installed on your system, you&rsquo;ll have to install it. You may use your system&rsquo;s &ldquo;package manager&rdquo; for this.

If you built Ruby before having installed the Tk dev package, it&rsquo;s 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 &ldquo;old&rdquo; one click installer has the Tk binaries, however you&rsquo;ll still need to install the Tk toolkit from ActiveState.

If you&rsquo;re using the new &ldquo;rubyinstaller&rdquo; then for 1.8.6 this might help or for 1.9 this might help

There&rsquo;s a precompiled gem which should work out-of-the-box: tk-win.

It includes sources and libraries directly from Hidetoshi NAGAI. It&rsquo;s 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 won&rsquo;t be necessary.

|