I’m looking into using Ruby/Tk for a major project. Maybe I’m crazy,
but I find its interface cleaner than that of FOX. I’m very
experienced with Perl/Tk, but I’m just getting started with the Ruby
port. Here are some questions and observations:
- There appears to be a bug in TkRoot.new (or possibly TkWindow.new).
On my Win2K box, the following code:
require ‘tk’
TkRoot.new do
puts "test"
end
produces:
test
test
The block is being called twice. This can be prevented with the
following code:
TkRoot.new do
return if @here
@here = true
...
end
This looks like a bug to me.
-
Do I have to install Tcl on *NIX boxes to use Ruby/Tk? I know I
can just redistribute the DLL’s on Windows, but how does this work on
NIX? Does Ruby/Tk come with everything it needs to run right out of
the box? -
How can I use TkTree? It looks like it’s in the tcltk-ext
package, but I’m not sure how to use this on Windows. Or Linux for
that matter. Does this also require Tcl to be installed? -
pack doesn’t accept a block, even though Programming Ruby implies
that this is so. I’ve written the following code to allow pack to
accept a block. It’s hackish, so maybe someone more familiar with the
Ruby/Tk internals can improve it:
class TkWindow
class PackContext
attr_reader :args
def initialize
@args = {}
end
def method_missing(sym, *args)
name = sym.id2name
@args[name] = args[0]
end
end
alias_method :old_pack, :pack
def pack(*args, &b)
if block_given?
pc = PackContext.new
pc.instance_eval(&b)
params = pc.args
else
params = *args
end
old_pack(params)
end
end
Then you can do things like
label.pack do
expand 1
fill "both"
end
which is kind of useful to me.
- Are there any special reasons not to use Tk? I need a toolkit
with a clean interface and small footprint.
Thanks in advance for your help,
Bill Atkins