问题描述
我正在尝试创建一个嵌入在Tkinter窗口中的实时Matplot图。 我有一个仅使用静态堆栈图显示的图形,但是当我创建动画时,什么也没有发生,动画实例也没有出现,请转到我的动画方法。 (它应该在“动画之前”和“动画之后”之间的动画方法中每秒打印“ [内部动画]”。)
import tkinter as tk
from matplotlib.backends.backend_tkagg import figureCanvasTkAgg,NavigationToolbar2Tk
from matplotlib.figure import figure
import matplotlib.animation as animation
class MainWindow:
def __init__(self,master):
self.master = master
# graph
self.fig = figure(figsize=(3,4),dpi=100)
# self.ax = self.fig.add_subplot()
# static = self.ax.stackplot([1,2,3,4,5],[2,5,7,11],[1,1],labels=['A','B'])
# self.fig.legend(loc='upper left')
print("Before Ani.")
ani = animation.FuncAnimation(self.fig,self.animate,interval=1000)
print("After Ani.")
canvas = figureCanvasTkAgg(self.fig,self.master)
canvas.draw()
canvas.get_tk_widget().pack(fill=tk.BOTH,expand=True)
def animate(self):
print("[Inside Animation]")
if __name__ == '__main__':
root = tk.Tk()
root.title("Flick Electric Price Meter")
root.geometry('200x100')
main = MainWindow(root)
root.mainloop()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)