Ruby/Tk

E

Erik Boling

I have been looking for a good ruby GUI, and TK seems to be easiest
for me. I am quite new to programing in general, so bare with me if i'm
using the wrong "wordage" for things. I have been creating simple
programs, i.e basic skills math tests. But i have gotten bored/ annoyed
of cmd prompt. I was wondering does anyone know of any good tutorials
on how to program w/ TK. I have found some, but they are all very basic
and only go as far as explaining how to put buttons and text on the
window. I was trying to get my GUI more *active* like being able to
output and input information. Perhaps there is a better choice for a
Ruby GUI that someone might recommend that has more extensive easier
tutorials?
Thanks for the help :)!
 
M

Morton Goldberg

I have been looking for a good ruby GUI, and TK seems to be
easiest
for me. I am quite new to programing in general, so bare with me if
i'm
using the wrong "wordage" for things. I have been creating simple
programs, i.e basic skills math tests. But i have gotten bored/
annoyed
of cmd prompt. I was wondering does anyone know of any good tutorials
on how to program w/ TK. I have found some, but they are all very
basic
and only go as far as explaining how to put buttons and text on the
window. I was trying to get my GUI more *active* like being able to
output and input information. Perhaps there is a better choice for a
Ruby GUI that someone might recommend that has more extensive easier
tutorials?

AFAIK there isn't anything much more than introductory material
available in English on-line for Ruby/Tk. It's really too bad because
Ruby/Tk provides a broad and deep range of GUI capabilities. After I
(rather quickly) reached the limitations of the available tutorials,
I turned to

<http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/
sample/>

This is not a tutorial but a repository of example code. I have
learned much from studying these examples. I recommend you take a
look at them. Also, if you have a question about a specific Ruby/Tk
element you can post it here. I'll answer it if I can. But more to
the point, NAGAI Hidetoshi (the implementor/maintainer of Ruby/Tk)
often answers such question, and his answers are always illuminating.
I have learned a great deal from them.

Regards, Morton
 
R

Ron Fox

Tk started off as the graphical tool kit for a scripting language
called Tcl/Tk. I have a strong feeling that once you grasp the basics
of Ruby/Tk you can get some good ideas about how to use it by searching
for stuff that describes what you want to do at
http://wiki.tcl.tk (the Tcl/Tk) wiki.

You'll need to translate the Tcl code that you see there to the
Ruby/Tk idioms but Tcl/Tk is pretty easy to read most of the time.
 
E

Erik Boling

Ron said:
You'll need to translate the Tcl code that you see there to the
Ruby/Tk idioms but Tcl/Tk is pretty easy to read most of the time.

I'm not sure how to start off translating all this code justt see a bit
might help, anyone know how to trans. this?
 
E

Erik Boling

Erik said:
I'm not sure how to start off translating all this code justt see a bit
might help, anyone know how to trans. this?

sorry hit enter =(! ok, this is the code!.....: #!
/usr/local/bin/wish8.1 button .b -text 0 -command {.b config -text [expr
[.b cget -text]+1]}
pack .b ;#RS
 
H

Hidetoshi NAGAI

From: Erik Boling <[email protected]>
Subject: Re: Ruby/Tk
Date: Sun, 2 Dec 2007 08:04:46 +0900
Message-ID: said:
I'm not sure how to start off translating all this code justt see a bit
might help, anyone know how to trans. this?

sorry hit enter =(! ok, this is the code!.....: #!
/usr/local/bin/wish8.1 button .b -text 0 -command {.b config -text [expr
[.b cget -text]+1]}
pack .b ;#RS

Follwoings are some of the examples.
Please see also
<http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138653>.

-----<ex.1>---------------------------------------------
b = TkButton.new:)text=>'0', :command=>proc{b.text = b.text.to_i + 1}).pack
--------------------------------------------------------

-----<ex.2>--------------------------------------------
b = TkButton.new('text'=>'0', 'command'=>proc{b.text = b.text.to_i + 1}).pack
--------------------------------------------------------

-----<ex.3>---------------------------------------------
b = TkButton.new:)text=>'0', :command=>proc{b.text(b.text.to_i + 1)}).pack
--------------------------------------------------------

-----<ex.4>---------------------------------------------
b = TkButton.new:)text=>'0', :command=>proc{b[:text] = b.text.to_i + 1}).pack
--------------------------------------------------------

-----<ex.5>---------------------------------------------
b = TkButton.new:)text=>'0', :command=>proc{b['text'] = b.text.to_i + 1}).pack
--------------------------------------------------------

-----<ex.6>---------------------------------------------
TkButton.new:)text=>'0'){|b|
command{b.text = b.text.to_i + 1}
}.pack
--------------------------------------------------------

-----<ex.7>---------------------------------------------
TkButton.new:)text=>'0'){
command{self.text = self.text.to_i + 1}
}.pack
--------------------------------------------------------

-----<ex.8>---------------------------------------------
TkButton.new:)text=>'0'){
command{text(text.to_i + 1)}
}.pack
--------------------------------------------------------

-----<ex.9>---------------------------------------------
TkButton.new{
text 0
command{text(text.to_i + 1)}
pack
}
--------------------------------------------------------

-----<ex.10>--------------------------------------------
cnt = 0
b = TkButton.new:)text=>cnt, :command=>proc{b.text = (cnt += 1)}).pack
--------------------------------------------------------

-----<ex.11>--------------------------------------------
TkButton.new{
cnt = 0
text cnt
command{text(cnt+=1)}
pack
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Ruby TK 1
Installing Tk 3
Ruby/tk Help Please 19
Tk : non blocking Tk.mainloop 20
Ruby 1.9.1 build and Tk 1
Ruby/Tk 4
Ruby + tk 1
RuntimeError using Tk with Ruby 1

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top