O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required