[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Only one root window in RubyTk

Len Lawrence

11/21/2006 11:29:00 AM

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

4 Answers

Morton Goldberg

11/23/2006 12:41:00 AM

0

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

> 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



Len Lawrence

11/23/2006 7:32:00 PM

0

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

> On Nov 22, 2006, at 5:50 PM, Len Lawrence wrote:
>
>> 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?
>>
>
> 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


Morton Goldberg

11/25/2006 2:49:00 AM

0

On Nov 24, 2006, at 2:51 PM, Len Lawrence 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/...
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/...

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

Len Lawrence

11/26/2006 12:45:00 AM

0

On Sat, 25 Nov 2006 11:48:49 +0900, Morton Goldberg 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/...
> http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/...
>
> 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