Skip to content

Commit fca4baf

Browse files
committed
embedding_in_tk examples: improve the first, delete the second
1 parent 13a11b4 commit fca4baf

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

examples/user_interfaces/embedding_in_tk.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
23
import matplotlib
34
matplotlib.use('TkAgg')
45

@@ -9,11 +10,8 @@
910
import Tkinter as Tk
1011
import sys
1112

12-
def destroy(e): sys.exit()
13-
1413
root = Tk.Tk()
1514
root.wm_title("Embedding in TK")
16-
#root.bind("<Destroy>", destroy)
1715

1816

1917
f = Figure(figsize=(5,4), dpi=100)
@@ -33,7 +31,16 @@ def destroy(e): sys.exit()
3331
toolbar.update()
3432
canvas._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

3942
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+

examples/user_interfaces/embedding_in_tk2.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)