-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguitest.py
More file actions
77 lines (55 loc) · 1.7 KB
/
guitest.py
File metadata and controls
77 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import matplotlib
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
# implement the default mpl key bindings
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
root = Tk.Tk()
root.wm_title("Embedding in TK")
f = Figure(figsize=(3,2), dpi=150)
a = f.add_subplot(211)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
a.plot(t, s)
b = f.add_subplot(212)
b.plot(t, sin(4*pi*t))
f2 = Figure(figsize=(3,3), dpi=150)
c = f2.add_subplot(111)
c.plot(t, sin(6*pi*t))
# c = f.add_subplot(221)
#
# c.plot(t, sin(6*pi*t))
# a tk.DrawingArea
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
# canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
#
# toolbar = NavigationToolbar2TkAgg(canvas, root)
# toolbar.update()
canvas._tkcanvas.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)
canvas2 = FigureCanvasTkAgg(f2, master=root)
canvas2.show()
canvas2._tkcanvas.pack(side=Tk.RIGHT, fill=Tk.BOTH, expand=1)
# def on_key_event(event):
# print('you pressed %s' % event.key)
# key_press_handler(event, canvas, toolbar)
#
# canvas.mpl_connect('key_press_event', on_key_event)
#
#
# def _quit():
# root.quit() # stops mainloop
# root.destroy() # this is necessary on Windows to prevent
# # Fatal Python Error: PyEval_RestoreThread: NULL tstate
#
# button = Tk.Button(master=root, text='Quit', command=_quit)
# button.pack(side=Tk.BOTTOM)
Tk.mainloop()
# If you put root.destroy() here, it will cause an error if
# the window is closed with the window manager.