From: Phlip Date: 2003-05-27T15:04:23+09:00 Subject: Tk: Call mainloop twice Rubies: The following code, when the user hits or clicks the little close gadget on your window, destroys the TkRoot singleton, so everything below the first Tk.mainloop won't work: require 'tk' canvas = TkCanvas.new() {width(400);height(300) } TkcText.new(canvas, 100, 200) { text 'hello world' } canvas.grid canvas.bind('Destroy') { |event| puts "going down" return if event.widget != @canvas Tk.quit } Tk.mainloop canvas = TkCanvas.new() {width(400); height(300) } TkcText.new(canvas, 200, 100) { text 'hello world' } canvas.grid Tk.mainloop The second call to TkCanvas.new dies with: bgerror failed to handle background error. Original error: c:/ruby/lib/ruby/1.7/tk.rb:358:in `call': return from proc-closure Error in bgerror: can't invoke "toplevel" command: application has been destroyed Witness my feeb attempt to tell the Tk.mainloop to gracefully exit instead of destroy everything inside itself. I tried to bind to the Destroy event. We may presume that the Destroy event itself takes down the Tk context. In this case, maybe there is some other event I can bind to, or some other binding site. I would prefer, for elaborate & irrelevant reasons, not to just add a stinkin' button one can click on to call the Tk.quit. And experiments with Tk.callback_break likewise bomb. Experiments opening another window, so the first Tk.mainloop would still feel useful when the canvas goes down, also failed. -- Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces