Adding the pause/unpause function

Since we need a single button to toggle between pause and unpause, we will again use the cycle() method from the itertools module. Define an attribute, as follows (see code 5.04view.py):

toggle_pause_unpause = itertools.cycle(["pause","unpause"])

Then, modify the command callback attached to the button, as follows:

def on_pause_unpause_button_clicked(self): action = next(self.toggle_pause_unpause) if action == 'pause':   self.player.pause() elif action == 'unpause':   self.player.unpause()

This takes care of the pause and unpause features of the program.

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.