Ralf Fassel wrote: > * "Phlip" <phlipcpp / yahoo.com> > | But what's "my_deletion_prevention_routine"? > > It's just any function you like to get called when the user presses > the button which causes the DELETE_WINDOW request (it's the `puts' in > your example). Usually it is some cleanup routine (eg, the same as > you would have under File->Exit), but it might also > be just (again, in Tk notation) > wm protocol {.} WM_DELETE_WINDOW { # do nothing } > wm protocol {.} WM_DELETE_WINDOW { wm withdraw {.} } I'm not asking how callbacks work. I'm asking, specifically, what to write in that location that makes this code not crash: require 'tk' top = TkRoot.new() canvas = TkCanvas.new(top) {width(400);height(300) } TkcText.new(canvas, 100, 200) { text 'hello world' } canvas.grid top.protocol('WM_DELETE_WINDOW', proc{puts 'huh?'}) Tk.mainloop canvas = TkCanvas.new() {width(400); height(300) } TkcText.new(canvas, 200, 100) { text 'hello world' } canvas.grid Tk.mainloop The way it currently works, you see a window, you close it, Tk tries to create another window, and crashes. Someone wrote "my_deletion_prevention_routine" because they assumed I knew how to prevent deletion. > In these examples I assume you know what you're doing there, and that > your users have some other means of terminating the application ;-) It's not an application. But, with the current control flow, merely adding a handler to the event does not prevent the event from propagating to the window, destroying it, halting the Tk mainloop, and destroying the Tk singleton. I don't want the Tk singleton destroyed. I want to be able to create a new window after Tk.mainloop exits. Some have offered, "create two toplevel windows, so the other one stays up and keeps Tk.mainloop going". This also does not work, because I need Tk.mainloop to exit and not halt forever. The documentation says to use either quit or callback_break there. Both crash. -- Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces