Embedding in Tk example : Why bind destroy to sys.exit() ??

Hi all,

I was attempting to modify the file examples/embedding_in_tk.py so as to add a button allowing me to choose and (eventually) open a data file for plotting. Binding a function which uses tkFileDialog.askopenfilename() to a button was making the application stop with a "Fatal Python Error: PyEval_RestoreThread: NULL state", after the function returned.

eg:
Tk.Button(master=root, text="Open", command=lambda : sys.stdout.write(tkFileDialog.askopenfilename()).pack()

After you click the button and select the file, then the application stops with the complaint about threading as root.destroy has been called by the tkFileDialog (presumably on itself)

So is there some reason for the bits of the example?:

def destroy(e) : sys.exit()
[...]
root.bind("<destroy>",destroy)

changing to:

def destroy(e):
   print "root destroy called"
   sys.exit()

confirms the origin of the problem. Is there some reason for the method used? Commenting out the offending bind to root might make the example a little bit easier for slow thinking people such as myself to modify and then get going with... I realise I might have been going about things the wrong way to randomly modify an example I don't fully understand, but the graphs looked so nice and tempting...

Perhaps other (scientist) programmers might be able to get going more easily if this little trap is removed? The quality and speed of the plotting is fantastic, I'm extremely impressed!

Thanks,

Jon