Forum: Ruby TK/Ruby Instructions

40b399cefcca7a20e499ca42e33518e0?d=identicon&s=25 Todd Fox (rabidfox)
on 2016-07-10 03:05
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
0d130f179f85401f248e6ebc2ef8292f?d=identicon&s=25 Eric C. (eric_c)
on 2016-07-11 07:09
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
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-07-11 17:38
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
40b399cefcca7a20e499ca42e33518e0?d=identicon&s=25 Todd Fox (rabidfox)
on 2016-07-11 22:13
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.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-07-12 06:45
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/)?
40b399cefcca7a20e499ca42e33518e0?d=identicon&s=25 Todd Fox (rabidfox)
on 2016-07-12 17:32
I was discussing GTK with Eric and TK with you.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-07-12 18:07
Ah, sorry, got it now.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-07-12 18:11
BTW, one other alternative is FXRuby:
http://www.fxruby.org/doc/book.html
40b399cefcca7a20e499ca42e33518e0?d=identicon&s=25 Todd Fox (rabidfox)
on 2016-07-13 23:52
Thank you. I'll check that out.
0d130f179f85401f248e6ebc2ef8292f?d=identicon&s=25 Eric C. (eric_c)
on 2016-07-25 03:51
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
40b399cefcca7a20e499ca42e33518e0?d=identicon&s=25 Todd Fox (rabidfox)
on 2016-08-07 02:11
That's part of my problem. I can't find GTK3 anywhere and I've searched
all over the internet.
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2016-08-07 20:27
I would use ruby-gnome / ruby-gtk too. I use it as well. :)

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.
D9826083ab7e5e65ddeb00dc88297cee?d=identicon&s=25 Brayden Mossey (wir3sandfir3s)
on 2016-09-18 19:10
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!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.