embedding plot in tk upgedatet
This commit is contained in:
parent
0ebe0cad84
commit
b5851c5895
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "C:\\Users\\server2\\Anaconda3\\python.exe"
|
||||
}
|
||||
BIN
__pycache__/CCDfiles.cpython-37.pyc
Normal file
BIN
__pycache__/CCDfiles.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/CCDhelp.cpython-37.pyc
Normal file
BIN
__pycache__/CCDhelp.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/CCDmenusetup.cpython-37.pyc
Normal file
BIN
__pycache__/CCDmenusetup.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/CCDpanelsetup.cpython-37.pyc
Normal file
BIN
__pycache__/CCDpanelsetup.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/CCDplots.cpython-37.pyc
Normal file
BIN
__pycache__/CCDplots.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/CCDserial.cpython-37.pyc
Normal file
BIN
__pycache__/CCDserial.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-37.pyc
Normal file
BIN
__pycache__/config.cpython-37.pyc
Normal file
Binary file not shown.
60
matplot_in_tk.py
Normal file
60
matplot_in_tk.py
Normal file
@ -0,0 +1,60 @@
|
||||
## https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html
|
||||
import matplotlib
|
||||
matplotlib.use('TkAgg')
|
||||
|
||||
|
||||
|
||||
from numpy import arange, sin, pi
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
|
||||
# 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=(5, 4), dpi=100)
|
||||
a = f.add_subplot(111)
|
||||
t = arange(0.0, 3.0, 0.01)
|
||||
s = sin(2*pi*t)
|
||||
|
||||
a.plot(t, s)
|
||||
|
||||
|
||||
# a tk.DrawingArea
|
||||
canvas = FigureCanvasTkAgg(f, master=root)
|
||||
canvas.draw()
|
||||
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
|
||||
|
||||
toolbar = NavigationToolbar2Tk(canvas, root)
|
||||
toolbar.update()
|
||||
canvas._tkcanvas.pack(side=Tk.TOP, 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.
|
||||
Loading…
Reference in New Issue
Block a user