From: nagai@... Date: 2003-03-11T13:46:18+09:00 Subject: Re: [Q] How to destroy a TkToplevel window Hi, From: Daniel Carrera Subject: [Q] How to destroy a TkToplevel window Date: Tue, 11 Mar 2003 10:26:14 +0900 Message-ID: <20030311012607.GA3973@math.umd.edu> > I have a main window with a button called 'Callback'. If you click on > it you get the dialog, which has a 'Cancel' button, which simply calls > the 'destroy' method on the TkToplevel window. When you click on it > though, I get an error pop-up saying: > > Error: invalid command name > ".w0005.w0006" > > Does anyoone know what I'm doing wrong? Or is there an easier way to do > what I want? Here is my code: The reason of this problem is the rule of binding operation of Tk. Please see the explanation of 'BindTag' on Tcl/Tk documents. You binded your callback operation to the 'Cancel' button. When 'ButtonRelease-1', the operation is executed at first, because the operation is binded to the widget. And the button will be destroyed the the toplevel widget. But, based on BindTag rule, Button widget binding is executed after the widget binding. It executes the 'command' option procedure (in this case, NULL procedure) of destroyed button widget. There are two ways to avoid this problem. One is to use command option instead of binding. ----------------------------------------------------------------- button_quit.command { dialog.destroy } ----------------------------------------------------------------- And the other is to use Tk.callback_break to stop callback operations. ----------------------------------------------------------------- button_quit.bind("ButtonRelease-1") { dialog.destroy Tk.callback_break } ----------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)