Open hmhjapan opened 3 years ago
import tkinter
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import numpy as np
root = tkinter.Tk()
root.wm_title("Embedding in Tk")
fig = Figure(figsize=(5, 4), dpi=100)
t = np.arange(0, 3, .01)
years =[1950,1960,1970,1980,1990,2000,2010]
gdp=[300.2,543.3,1075.9,2862.5,5979.6,10289.7,14958.3]
fig.add_subplot(111).plot(years,gdp,color='red',marker='o')
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
def on_key_press(event):
print("you pressed {}".format(event.key))
key_press_handler(event, canvas, toolbar)
canvas.mpl_connect("key_press_event", on_key_press)
def _quit():
root.quit()
root.destroy()
button = tkinter.Button(master=root, text="Quit", command=_quit)
button.pack(side=tkinter.BOTTOM)
tkinter.mainloop()
Above is the source code of tkinter ,How to take and assemble two source code files? thank you!
I am sorry I am not much of an expert in TkInter. Have only played with it once or twice.
There is an example you can look at here: https://github.com/matplotlib/mplfinance/wiki/TkInter-Example
And some additional sample code here: https://github.com/matplotlib/mplfinance/issues/304
I would like to have a one or two good mplfinance tkinter demos to post here in the repository, but for me to do it myself I would probably have to spend a full couple of days learning tkinter and creating the demos, and I just don't have that time presently. Hopefully someone reading this who is well versed in tkinter will decide to help our and contribute an example or two to this repository.
Please let me know if the above links help out. All the best. --Daniel
Ask anything you want about mplfinance usage, project philosophy and/or priorities, or anything else related to mplfinance. Display the following animation graph on the tkinter,environment:python3.6 +windows10 desktop Below is mpf_animation_demo1.py: