# Ruby/Tk

**URL:** <https://rubytalk.org/t/ruby-tk/42626>\
**Category:** ruby-talk\
**Created:** [30 November 2007 05:04 UTC](https://rubytalk.org/t/ruby-tk/42626 "2007-11-30T05:04:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Boling](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@Erik\_Boling](https://rubytalk.org/u/Erik_Boling)\
**Post date:** [30 November 2007 05:04 UTC](https://rubytalk.org/t/ruby-tk/42626/1 "2007-11-30T05:04:29Z")

</div>

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 :)!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Morton\_Goldberg](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Morton\_Goldberg](https://rubytalk.org/u/Morton_Goldberg)\
**Post date:** [30 November 2007 06:20 UTC](https://rubytalk.org/t/ruby-tk/42626/2 "2007-11-30T06:20:03Z")

</div>

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/&gt](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/sample/&gt);

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

> **···**
>
> On Nov 30, 2007, at 12:04 AM, Erik Boling wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;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?

---

<div class="post-metadata">

**Author:** ![Ron\_Fox](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Ron\_Fox](https://rubytalk.org/u/Ron_Fox)\
**Post date:** [30 November 2007 12:25 UTC](https://rubytalk.org/t/ruby-tk/42626/3 "2007-11-30T12:25:16Z")

</div>

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](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.

Morton Goldberg wrote:

> **···**
>
> > On Nov 30, 2007, at 12:04 AM, Erik Boling wrote:
> > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;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/](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

---

<div class="post-metadata">

**Author:** ![Erik\_Boling](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@Erik\_Boling](https://rubytalk.org/u/Erik_Boling)\
**Post date:** [1 December 2007 23:03 UTC](https://rubytalk.org/t/ruby-tk/42626/4 "2007-12-01T23:03:46Z")

</div>

Ron Fox wrote:

> 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?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Erik\_Boling](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@Erik\_Boling](https://rubytalk.org/u/Erik_Boling)\
**Post date:** [1 December 2007 23:04 UTC](https://rubytalk.org/t/ruby-tk/42626/5 "2007-12-01T23:04:46Z")

</div>

Erik Boling wrote:

> Ron Fox wrote:
> 
> > 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?

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://rubytalk.org/u/Hidetoshi_NAGAI)\
**Post date:** [6 December 2007 06:51 UTC](https://rubytalk.org/t/ruby-tk/42626/6 "2007-12-06T06:51:23Z")

</div>

Message-ID: \<89ddcaa365b83fbdde7c6fbaca328792@ruby-forum.com\>

> \> 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&gt;\](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138653&gt;%5C).

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

> **···**
>
> From: Erik Boling \<schmode93@yahoo.com\>  
> Subject: Re: Ruby/Tk  
> Date: Sun, 2 Dec 2007 08:04:46 +0900  
> --------------------------------------------------------
> 
> -----\<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|  
> &nbsp;&nbsp;&nbsp;command{b.text = b.text.to\_i + 1}  
> }.pack  
> --------------------------------------------------------
> 
> -----\<ex.7\>---------------------------------------------  
> TkButton.new(:text=\>'0'){  
> &nbsp;&nbsp;&nbsp;command{self.text = self.text.to\_i + 1}  
> }.pack  
> --------------------------------------------------------
> 
> -----\<ex.8\>---------------------------------------------  
> TkButton.new(:text=\>'0'){  
> &nbsp;&nbsp;&nbsp;command{text(text.to\_i + 1)}  
> }.pack  
> --------------------------------------------------------
> 
> -----\<ex.9\>---------------------------------------------  
> TkButton.new{  
> &nbsp;&nbsp;&nbsp;text 0  
> &nbsp;&nbsp;&nbsp;command{text(text.to\_i + 1)}  
> &nbsp;&nbsp;&nbsp;pack  
> }  
> --------------------------------------------------------
> 
> -----\<ex.10\>--------------------------------------------  
> cnt = 0  
> b = TkButton.new(:text=\>cnt, :command=\>proc{b.text = (cnt += 1)}).pack  
> --------------------------------------------------------
> 
> -----\<ex.11\>--------------------------------------------  
> TkButton.new{  
> &nbsp;&nbsp;&nbsp;cnt = 0  
> &nbsp;&nbsp;&nbsp;text cnt  
> &nbsp;&nbsp;&nbsp;command{text(cnt+=1)}  
> &nbsp;&nbsp;&nbsp;pack  
> }  
> --------------------------------------------------------
> 
> -----\<ex.12\>---------------------------------------------  
> v = TkVariable.new(0)  
> TkButton.new(:textvariable=\>v, :command=\>proc{v.numeric += 1}).pack  
> --------------------------------------------------------  
> --  
> Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
