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 play/stop function

Now that we have a playlist and a Player class that can play audio, playing audio is simply about updating the current track index and calling the play method. 

Accordingly, let's add an attribute, as follows (see code 5.04view.py):

current_track_index = 0 

Furthermore, the Play button should act as a toggle between the play and stop functions. The Python itertools module provides the cycle method, which is a very convenient way to toggle between two or more values.

Accordingly, import the itertools module and define a new attribute, as follows (see code 5.04view.py):

toggle_play_stop = itertools.cycle(["play","stop"]) 

Now, every time we call next(toggle_play_stop), the value returned toggles between the ...

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