Are TkRoot Objects Destroyed Twice?

I just started building a small RubyTk application, created a TkRoot object, and added an event callback for the “Destroy” event.


root=TkRoot.new({'title'=>"Some Name"})
root.bind("Destroy", proc {puts "Goodbye, cruel world!"})

When I click the little ‘X’ in the corner, “Goodbye, cruel world!” is echoed twice.
How can I make the callback function be invoked only once?

I just created a sample application with the exact same code you posted, and the “Goodbye cruel world!” string is only echoed once. Can you post the full code, and tell me which version of Ruby you’re using?

Thanks,

I don’t want to post the full code because it is a little program on which I am working in Ruby 1.8. I have a canvas inside that TkRoot. Could it be that because of the canvas the callback is invoked twice?

It does seem to be because of the canvas, because when I add a canvas to my demo I get the double echo you’re talking about. I can’t find much online documentation for TK so it’s hard to tell why the callback is being called a second time.

Found a solution: add a frame directly under the root, and place the widgets in the frame. Bind the “Destroy” event to the frame, not to the root.