Only one root window in RubyTk

L

Len Lawrence

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']
 
M

Morton Goldberg

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']

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.

<code>
#! /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
</code>

<results>
#<TkRoot:0x502adc @path=".">
#<TkToplevel:0x5025dc @classname="Toplevel", @screen=nil,
@path=".w00000", @db_class=TkToplevel>
</results>

Hope this helps.

Regards, Morton
 
L

Len Lawrence

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.

<code>
#! /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
</code>

<results>
#<TkRoot:0x502adc @path=".">
#<TkToplevel:0x5025dc @classname="Toplevel", @screen=nil,
@path=".w00000", @db_class=TkToplevel>
</results>

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
 
M

Morton Goldberg

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://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
 
L

Len Lawrence

------ 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://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
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top