D
David Tran
I forgot which old version is, on that old version, the widget.pack
method always returns nil.
So people have to write something like:
b =3D TkButton.new {
pack
}
Now the pack returns self, what's great improvement, so we can write
something like:
b =3D TkButton.new.pack.command { puts "Hello" }
Now, my ruby version is : ruby 1.8.2 (2004-12-25) [i386-mswin32]
and my Tcl/Tk version is : 8.4
I have some Ruby/Tk design questions :
(1) Layout Manager:
there are:
widget.pack ; TkPack.pack ; Tk.pack
widget.grid ; TkGrid.grid ; Tk.grid
widget.place ; TkPlace.place
methods, why there is no Tk.place method ?
This seems inconsistent for me.
(2) Since we try to wrap Tcl/Tk on OO, why some Tcl commands are not
treat like options ?
Most options have getter and setter method, there are many way to do
it, for example:
# setter
button.bg =3D :red
button.bg
red)
button.configure
bg, :red)
# getter
puts button.bg
puts button.cget
bg)
Now, for example, root.title and root.iconbitmap ... etc are command
but not options on Tcl/Tk language.
But, I feel this will be nice if we "wrap" them like options, so we
can write something like:
TkRoot.new
title=3D>'Hello') or
TkButton.new
text=3D>'set title').command { Tk.root.title =3D "some title"=
}
For me, it seems title is just like an option for TkRoot.
(But in current version, it is not, so I cannot use :title=3D>... or
root.title =3D ... syntax )
(3)
require 'tk'
c =3D TkCanvas.new.pack
TkcRectangle.new(c, 10, 10, 50, 50)
Tk.mainloop
The above code works fine, but if I rewrite it to become
require 'tk'
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop
I got this error: uninitialized constant TkcRectangle (NameError)
Rewrite it again like:
require 'tk'
TkCanvas
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop
It works fine again.
So, what's going wrong with:
require 'tk' ; TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50) ; Tk.mai=
nloop
Why should I reference TkCanvas ( at least class ) first ?
Thank you.
method always returns nil.
So people have to write something like:
b =3D TkButton.new {
pack
}
Now the pack returns self, what's great improvement, so we can write
something like:
b =3D TkButton.new.pack.command { puts "Hello" }
Now, my ruby version is : ruby 1.8.2 (2004-12-25) [i386-mswin32]
and my Tcl/Tk version is : 8.4
I have some Ruby/Tk design questions :
(1) Layout Manager:
there are:
widget.pack ; TkPack.pack ; Tk.pack
widget.grid ; TkGrid.grid ; Tk.grid
widget.place ; TkPlace.place
methods, why there is no Tk.place method ?
This seems inconsistent for me.
(2) Since we try to wrap Tcl/Tk on OO, why some Tcl commands are not
treat like options ?
Most options have getter and setter method, there are many way to do
it, for example:
# setter
button.bg =3D :red
button.bg
button.configure
# getter
puts button.bg
puts button.cget
Now, for example, root.title and root.iconbitmap ... etc are command
but not options on Tcl/Tk language.
But, I feel this will be nice if we "wrap" them like options, so we
can write something like:
TkRoot.new
TkButton.new
}
For me, it seems title is just like an option for TkRoot.
(But in current version, it is not, so I cannot use :title=3D>... or
root.title =3D ... syntax )
(3)
require 'tk'
c =3D TkCanvas.new.pack
TkcRectangle.new(c, 10, 10, 50, 50)
Tk.mainloop
The above code works fine, but if I rewrite it to become
require 'tk'
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop
I got this error: uninitialized constant TkcRectangle (NameError)
Rewrite it again like:
require 'tk'
TkCanvas
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop
It works fine again.
So, what's going wrong with:
require 'tk' ; TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50) ; Tk.mai=
nloop
Why should I reference TkCanvas ( at least class ) first ?
Thank you.