所以我的图形动画效果很好,但是当我启动 GUI 时它总是在后台运行。但我只希望它在我按下“开始”按钮时启动。我已经完成了一项工作,它只是将间隔增加得非常高,而且它有点工作,但我知道它不是一个修复。而且我不确定如何使用按钮进行操作。
class PageFive(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
def animate(i):
c = app.cursor
c.execute("SELECT time, windspeed FROM data")
fetch = c.fetchall()
Xaxes = [x for (x, y) in fetch]
Yaxes = [y for (x, y) in fetch]
pltYaxes = np.array(Yaxes)
pltXaxes = np.array(Xaxes)
a.clear()
a.plot(pltXaxes,pltYaxes)
back = tk.Button(self, text="back",height = 2, width = 13,command=lambda: controller.show_frame(PageTwo), bg='green', fg='white', font=('helvetica', 15, 'bold')) #
back.pack()
label = ttk.Label(self, text="Windspeed", font=LARGE_FONT)
label.pack(pady=10,padx=10)
canvas = FigureCanvasTkAgg(f, master=self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
toolbar = NavigationToolbar2Tk( canvas, self )
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.ani = animation.FuncAnimation(f,animate, interval=5000)