TK/Ruby Instructions

I have skimmed through my books, I have looked online for tutorials, and
I have searched Amazon for other books. I cannot find anything on
TK/Ruby that makes any sense. Or very much information either. It’s
really hindering me, because I don’t know how to use GTK, but TK is
installed automatically with Ruby. I really don’t need much complexity,
as just basic codes.

Does anyone know of a book, a website, a help file, a PDF, anything…
anything at all… that clearly describes how to use TK with Ruby? Any
advice is appreciated.

  • Todd

Sorry, I don’t know tk, but perhaps you can try my program, visualruby:

You can do a great deal without having to know GTK. It is written in
GTK, and if you get deeper into it, you will need to use the GTK
classes, but there is extensive documentation here:

Visualruby will make creating a GTK program much easier. And there are
lots of examples.


Most languages, which use a Tk interface, assume that the programmer
“knows Tk already and just wants to have it accessible from his favorite
language”. This applies to the Tk bindings not only for Ruby, but also
Perl, Python and so on.

Maybe you find this Tutorial helpful:

This could give you a starting point, and you will get a feeling on how
Tk is mapped to Ruby. I think most people start with such introductions,
and once they get a feeling on how the mapping was done, use then the
original Tk documentation as a reference.


Thank you both for your advice.

I actually tried to install Visual Ruby, but could not get it to work. I
also have Glade GTK 2. I could not find a version for GTK 3, and I have
done extensive searching.

Part of my problem with TK is that the code has to be modified to go
with Ruby, and I don’t know all the modifications.

So, yeah, I’m really lost on both issues.

I’m now a bit confused: Are we talking about Tk
(Index of Classes & Methods in tk: Ruby Standard Library Documentation (Ruby 1.9.3)) or GTK

I was discussing GTK with Eric and TK with you.

Ah, sorry, got it now.

BTW, one other alternative is FXRuby:

Thank you. I’ll check that out.

That’s part of my problem. I can’t find GTK3 anywhere and I’ve searched
all over the internet.

Hi again:

visualruby works great with gtk3. I’ve updated it several times lately.
If you go to, there are download instructions. If you
have any problems, just let me know. As far as I know it works on all


I would use ruby-gnome / ruby-gtk too. I use it as well. :slight_smile:

People who use tk are very shy and hesitant to admit to it.

Advantage is that these are available by default and I assume
you got the hello world button already working right?

As for examples and docu, have a look here:

It works on windows too, but I personally use linux simply because
I can be much more productive when writing code. (Ruby makes windows
less annoying though, and bash is available in the latest windows
too by default as far as I am aware + ubuntu or something like

The second link is a wiki, it is quite helpful although lagging
a bit behind in documentation. See the official gtk3 page,
developer API documentation if you need help.

There is an example with the download for ruby-gnome, called
misc.rb or so, have a look in the directory after downloading
it. It showcases what ruby-gnome can do or ruby-gtk respectively,
also gtk2 btw; gtk3 should work fine too.

The examples all comes with the source code. If you know a bit
about ruby tweaking things to your working will be very very
easy eventually.

require 'gtk2'

text = 'Hello world!'
window =
button =
button.signal_connect(:clicked) { puts text }
window.add button
window.border_width = 10

require ‘gtk3’ should work too if you compile the bindings.

How do you assign variables to text widgets, or how can you delete
everything in a text widget instead of a set range? Thanks!