I didn't post all the code here for the sake of not bombing the newsgroup. The complete example is available here: http://www.johnjohnsonsoftware.com/ruby/oopiertk.zip Regards, JJ -- Be Kind, Be Careful, Be Yourself -- Solid, reliable software at reasonable prices http://www.johnjohnsonsoftware.com "Conrad Schneiker" <schneik / us.ibm.com> wrote in message news:OF0930C0C4.5F469B51-ON85256A42.002056C9 / raleigh.ibm.com... > John Johnson wrote: > > # Using Tk with Ruby (or any other language) has always seemed a > # little convoluted. Ruby's scoping for blocks makes this even more > # so, since the blocks passed to command are scoped when the command > # is set, not when it's running. This leads to: > # [...] > # Of course you have no idea what a p is, so you have to search back > # through the source to find it. I've been toying with classes that > # allow me to do the following: > # [...] > # As you can see, I have defined methods like onClick for Buttons, > # onCheck and onUncheck for CheckButtons, etc. Not demonstrated here > # are methods such as onEnter for FlatButton which allow you to do > # something when the mouse pointer enters the button. > > (Which would have been nice to include for the sake of a complete working > example.) > > # I think it's a whole heck of a lot more > # intuitive. Notice the @checkBtn.onUncheck for instance. The block it > # executes is defined where it is used. > # > # I plan to pursue this further, what do you folks think? > > I certainly want to encourage such explorations since Ruby/Tk is > likely to remain something of a useful lowest common GUI denominator > for quite some time, if the experience of Perl and Python are any > indication. But I think there are others better qualified to comment > on the merits of your particular proposal. > > In connection with your general question, I'd like to ask if you or > others are familiar with John E. Grayson's book, "Python and Tkinter > Programming", which proclaims itself to be "a clean, object-oriented > interface to the Tcl/Tk graphical toolkit" and which Guido claims is > "packed with well-explained examples that teach good Python habits". > > I don't know much Python and I haven't read this book, but I wonder if > others who do and have think that its approach could provide any > useful guidance for "OOP-ier" (cool neologism!) Ruby/Tk work. > > Conrad Schneiker > (This note is unofficial and subject to improvement without notice.) >