Managing continuous updates
Next, we will update the position of the seek bar knob and the elapsed play duration, as shown in the following screenshot:
This is nothing but a simple form of Tkinter-based animation.
The most common pattern of animating with Tkinter involves drawing a single frame and then calling the same method using the after
method of Tkinter, as follows:
def animate(self):
self.draw_frame()
self.after(500, self.animate)
Note
Once called, this function will keep updating frames once every 500 milliseconds. You can also add some conditions to break out of the animation loop.
Now that we know how to manage animations in Tkinter, let's use the pattern to define a method that takes care of these periodic updates.
Define a method named manage_periodic_updates_during_play
, which calls itself every one second to update the timer and the seek bar, as follows (see code 5.07
– view.py
):
def manage_periodic_updates_during_play(self):
self.update_clock()
...