File tree Expand file tree Collapse file tree 2 files changed +12
-47
lines changed Expand file tree Collapse file tree 2 files changed +12
-47
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python
2
+
2
3
import matplotlib
3
4
matplotlib .use ('TkAgg' )
4
5
9
10
import Tkinter as Tk
10
11
import sys
11
12
12
- def destroy (e ): sys .exit ()
13
-
14
13
root = Tk .Tk ()
15
14
root .wm_title ("Embedding in TK" )
16
- #root.bind("<Destroy>", destroy)
17
15
18
16
19
17
f = Figure (figsize = (5 ,4 ), dpi = 100 )
@@ -33,7 +31,16 @@ def destroy(e): sys.exit()
33
31
toolbar .update ()
34
32
canvas ._tkcanvas .pack (side = Tk .TOP , fill = Tk .BOTH , expand = 1 )
35
33
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 )
38
41
39
42
Tk .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