Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77d9500

Browse files
committed
Fix tkagg animation error at exit.
Apparently, with a small enough animation interval, tk does not have the time to fully proceed through FigureManagerTkAgg.show before the animation takes over. Removing the call to self.window.update (which had been added back in 2004 (6c96389), but seems unnecessary (including on Windows)) fixes the issue. Also update the animation example so that it can serve as manual test for the issue; changed the rate at which the data moves to keep it reasonable, and switched to None (= count()) as index iterable to avoid a jump every time we reach the end of the indices.
1 parent 6336f2d commit 77d9500

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

examples/animation/simple_anim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def animate(i):
19-
line.set_ydata(np.sin(x + i/10.0)) # update the data
19+
line.set_ydata(np.sin(x + i / 100)) # update the data
2020
return line,
2121

2222

@@ -25,6 +25,6 @@ def init():
2525
line.set_ydata(np.ma.array(x, mask=True))
2626
return line,
2727

28-
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
29-
interval=25, blit=True)
28+
ani = animation.FuncAnimation(
29+
fig, animate, init_func=init, interval=2, blit=True)
3030
plt.show()

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,6 @@ def destroy(*args):
555555
Gcf.destroy(self._num)
556556
self.canvas._tkcanvas.bind("<Destroy>", destroy)
557557
self.window.deiconify()
558-
# anim.py requires this
559-
self.window.update()
560558
else:
561559
self.canvas.draw_idle()
562560
# Raise the new window.

0 commit comments

Comments
 (0)