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

Tkinter and threading

One of the simplest ways that we can make our root window responsive is to use the root.update() method within our play_pattern loop. This updates the root.mainloop() method after each sound sample is played.

However, this is an inelegant method because the control is passed to the main loop with some staggering experienced in the GUI. Thus, you may experience a slight delay in the responses of other widgets in the Toplevel window.

Further, if some other event causes the method to be called, it could result in a nested event loop.

A better solution would be to run the play_pattern method from a separate thread.

Let's use the threading module of Python to play the pattern in a separate thread. This way, pygame will not ...

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