# Only one root window in RubyTk

**URL:** <https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977>\
**Category:** Ruby\
**Created:** [November 22, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977 "2006-11-22T23:52:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [November 22, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977/1 "2006-11-22T23:52:09Z")

</div>

I have just started using ruby after 15 years with Tcl/Tk/C/C++  
and have encountered a problem trying to create a second  
toplevel window. This was trivial in tcl. In ruby the second  
window has the same object reference as the first, so everything  
gets packed together.

Is this a bug or a feature of the ruby Tk implementation?

This is the extract:

$window[‘root’] = TkRoot.new { title “ttlog : version 2.2” }  
puts $window[‘root’]

$window[‘today’] = TkRoot.new { title “Todays news” }  
puts $window[‘news’]

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [November 23, 2006, 1:42am UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977/2 "2006-11-23T01:42:20Z")

</div>

On Nov 22, 2006, at 5:50 PM, Len L. wrote:

> $window[‘root’] = TkRoot.new { title “ttlog : version 2.2” }  
> puts $window[‘root’]
> 
> $window[‘today’] = TkRoot.new { title “Todays news” }  
> puts $window[‘news’]

AFAIK, you can’t have two root windows in Ruby/Tk. However, you can  
put up two windows by creating a toplevel window as the second window.

`
#! /usr/bin/env ruby -w
require “tk”
root = TkRoot.new { title “ttlog : version 2.2” }
p root
second = TkToplevel.new(root) { title “Todays news” }
p second
Tk.mainloop
` # #

Hope this helps.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [November 24, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977/3 "2006-11-24T22:03:11Z")

</div>

On Thu, 23 Nov 2006 09:41:27 +0900, Morton G. wrote:

> second = TkToplevel.new(root) { title “Todays news” }
> 
> Hope this helps.
> 
> Regards, Morton

Thanks Morton; just what I was looking for. In Tcl you use toplevel  
to create what I call a “root” window. The Pickaxe does not go  
into much detail - perlTk book in the post.

Thanks again, and apologies for the elementary question.

Len

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [November 25, 2006, 3:50am UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977/4 "2006-11-25T03:50:08Z")

</div>

On Nov 24, 2006, at 2:51 PM, Len L. wrote:

> Thanks Morton; just what I was looking for. In Tcl you use toplevel  
> to create what I call a “root” window. The Pickaxe does not go  
> into much detail - perlTk book in the post.

I must say, despite the advice in the Pickaxe book, I have not found  
perl/Tk documentation to be all that useful – that may be because I  
don’t know zip about perl. What I rely on, besides the Tcl/Tk man  
pages and the Tk documentation available on the web, are:

[http://raa.ruby-lang.org/project/rubytk\_en/](http://raa.ruby-lang.org/project/rubytk_en/)  
[http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/](http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/)

I recommend you look at these sites.

> Thanks again, and apologies for the elementary question.

No need for apologies. We all start from square one. I’m no Ruby/Tk  
expert. I’m on square two. I’ve asked even more elementary Ruby/Tk  
questions on this list myself and quite recently at that.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![tarazed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed8c4c/32.png) [@tarazed](https://www.ruby-forum.com/u/tarazed)\
**Post date:** [November 26, 2006, 1:52am UTC](https://www.ruby-forum.com/t/only-one-root-window-in-rubytk/76977/5 "2006-11-26T01:52:05Z")

</div>

On Sat, 25 Nov 2006 11:48:49 +0900, Morton G. wrote:

> ------ text excised -------------  
> I must say, despite the advice in the Pickaxe book, I have not found  
> perl/Tk documentation to be all that useful – that may be because I  
> don’t know zip about perl. What I rely on, besides the Tcl/Tk man  
> pages and the Tk documentation available on the web, are:
> 
> [http://raa.ruby-lang.org/project/rubytk\_en/](http://raa.ruby-lang.org/project/rubytk_en/)  
> [http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/](http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/)
> 
> I recommend you look at these sites.

Right, I have them bookmarked now. Will check them out later.

I am impressed with the ease and speed of development in ruby. It has  
taken about 12 days to to learn the basics and rewrite a user interface  
which needs to be in production by Tuesday. Bullet-proofing comes  
later.

The only outstanding problem is how to get BLT to work (for xy plots)  
but  
those websites above may have some answers.

1.upto(1000) { puts “Thanks” }

Len
