From: David Tran Date: 2005-08-02T06:53:52+09:00 Subject: Tk - Ruby/Tk core library design questions 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 = TkButton.new { pack } Now the pack returns self, what's great improvement, so we can write something like: b = 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 = :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=>'Hello') or TkButton.new(:text=>'set title').command { Tk.root.title = "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=>... or root.title = ... syntax ) (3) require 'tk' c = 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.mainloop Why should I reference TkCanvas ( at least class ) first ? Thank you.