class Widget { constructor {args} { set w .[lindex [split $this "::"] end] ;# here we hack object name to be [Tk] widget tree compatible # here parsing options while constructing widget, such as colors, layout, etc } destructor { destroy $w # btw. - we need to bind $w destroying event to delete $this object } protected { variable w ;# this is our widget path } # and here, whatever you need... }This allows to do the following:
Widget wid -some_option value pack .wid wid some_method delete widor
Widget some_frame.widget pack .some_frame.widgetetc.... and Itcl syntax allows to implement such widgets in very, very easy way! :)Have you some additional hints?
Sarnold 2005-07-16 -- Thanks for this work : I will probably use it for itins to build a itins::widget commandI almost always use tclkit as my Tcl interpreter, so I have to choose between incr Tcl and snit, that is just the way I came to building itins, trying as well as I can to get the best of both.LV Actually, since you are including tcllib in your starkit, why not include itk as well, and then you can use iwidgets and not have to write all the above code? The kinds of things you describe writing above is what was written and debugged in itk. Of course, another OO option you have is stooop, which is also in tcllib.SRIV I too use tclkit for all my apps, and would prefer to have a lightweight wrapper around itcl to make it more snit like. I'd rather not have to include iTk binaries for each platform. IMHO, itins with this code added may give me the performance and simplicity I've been looking for.See also itcled
Category Widget Category Object Orientation Category Itcl