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:

visualruby.net

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:

https://ruby-gnome2.osdn.jp/

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

Best,
Eric

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:

http://phrogz.net/programmingruby/ext_tk.html

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.

Ronald

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
(http://ruby-doc.org/stdlib-1.9.3/libdoc/tk/rdoc/index.html) or GTK
(http://www.gtk.org/)?

I was discussing GTK with Eric and TK with you.

Ah, sorry, got it now.

BTW, one other alternative is FXRuby:
http://www.fxruby.org/doc/book.html

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 visualruby.net, there are download instructions. If you
have any problems, just let me know. As far as I know it works on all
platforms.

Best,
Eric

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:

https://github.com/ruby-gnome2/ruby-gnome2
http://ruby-gnome2.osdn.jp/

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
that.)

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 = Gtk::Window.new
button = Gtk::Button.new(text)
button.signal_connect(:clicked) { puts text }
window.add button
button.show
window.border_width = 10
window.show
Gtk.main

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs