SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    Code:
    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?

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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?

  3. #3
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Louis Simoneau View Post
    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?

  4. #4
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •