File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python
2+
23import matplotlib
34matplotlib .use ('TkAgg' )
45
910import Tkinter as Tk
1011import sys
1112
12- def destroy (e ): sys .exit ()
13-
1413root = Tk .Tk ()
1514root .wm_title ("Embedding in TK" )
16- #root.bind("<Destroy>", destroy)
1715
1816
1917f = Figure (figsize = (5 ,4 ), dpi = 100 )
@@ -33,7 +31,16 @@ def destroy(e): sys.exit()
3331toolbar .update ()
3432canvas ._tkcanvas .pack (side = Tk .TOP , fill = Tk .BOTH , expand = 1 )
3533
36- #button = Tk.Button(master=root, text='Quit', command=sys.exit)
37- #button.pack(side=Tk.BOTTOM)
34+ def _quit ():
35+ root .quit () # stops mainloop
36+ root .destroy () # this is necessary on Windows to prevent
37+ # Fatal Python Error: PyEval_RestoreThread: NULL tstate
38+
39+ button = Tk .Button (master = root , text = 'Quit' , command = _quit )
40+ button .pack (side = Tk .BOTTOM )
3841
3942Tk .mainloop ()
43+ # If you put root.destroy() here, it will cause an error if
44+ # the window is closed with the window manager.
45+
46+
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments