8000 Cleanup embedding_in_tk, remove embedding_in_tk2. · matplotlib/matplotlib@2597f3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2597f3d

Browse files
committed
Cleanup embedding_in_tk, remove embedding_in_tk2.
embedding_in_tk2_sgskip is essentially a slightly simplified duplicate of embedding_in_tk_sgskip.
1 parent f56e001 commit 2597f3d

File tree

2 files changed

+20
-78
lines changed

2 files changed

+20
-78
lines changed

examples/user_interfaces/embedding_in_tk2_sgskip.py

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

examples/user_interfaces/embedding_in_tk_sgskip.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,26 @@
44
===============
55
66
"""
7-
import matplotlib
8-
matplotlib.use('TkAgg')
9-
10-
from numpy import arange, sin, pi
11-
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
12-
# implement the default mpl key bindings
13-
from matplotlib.backend_bases import key_press_handler
147

8+
from six.moves import tkinter as Tk
159

10+
from matplotlib.backends.backend_tkagg import (
11+
FigureCanvasTkAgg, NavigationToolbar2TkAgg)
12+
# Implement the default Matplotlib key bindings.
13+
from matplotlib.backend_bases import key_press_handler
1614
from matplotlib.figure import Figure
1715

18-
import sys
19-
if sys.version_info[0] < 3:
20-
import Tkinter as Tk
21-
else:
22-
import tkinter as Tk
23-
24-
root = Tk.Tk()
25-
root.wm_title("Embedding in TK")
16+
import numpy as np
2617

2718

28-
f = Figure(figsize=(5, 4), dpi=100)
29-
a = f.add_subplot(111)
30-
t = arange(0.0, 3.0, 0.01)
31-
s = sin(2*pi*t)
32-
33-
a.plot(t, s)
19+
root = Tk.Tk()
20+
root.wm_title("Embedding in Tk")
3421

22+
fig = Figure(figsize=(5, 4), dpi=100)
23+
t = np.arange(0, 3, .01)
24+
fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t))
3525

36-
# a tk.DrawingArea
37-
canvas = FigureCanvasTkAgg(f, master=root)
26+
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
3827
canvas.draw()
3928
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
4029

@@ -43,21 +32,23 @@
4332
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
4433

4534

46-
def on_key_event(event):
47-
print('you pressed %s' % event.key)
35+
def on_key_press(event):
36+
print("you pressed {}".format(event.key))
4837
key_press_handler(event, canvas, toolbar)
4938

50-
canvas.mpl_connect('key_press_event', on_key_event)
39+
40+
canvas.mpl_connect("key_press_event", on_key_press)
5141

5242

5343
def _quit():
5444
root.quit() # stops mainloop
5545
root.destroy() # this is necessary on Windows to prevent
5646
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
5747

58-
button = Tk.Button(master=root, text='Quit', command=_quit)
48+
49+
button = Tk.Button(master=root, text="Quit", command=_quit)
5950
button.pack(side=Tk.BOTTOM)
6051

6152
Tk.mainloop()
62-
# If you put root.destroy() here, it will cause an error if
63-
# the window is closed with the window manager.
53+
# If you put root.destroy() here, it will cause an error if the window is
54+
# closed with the window manager.

0 commit comments

Comments
 (0)
0