Python tip: Pausing

Ok, I’m going to start writing down things I learn about VPython.  First, a note.  If I say “VPython” or “Glowscript” – I’m really talking about the same thing.  In my usage, I will let VPython be a program in python with the visual module.  Hopefully, these things that I write will be the same for both platforms.

Now for today’s tip – how do you pause a program?  In the past, I have made these “start”-“pause” buttons.  It’s not super difficult to do, but there is some stuff in there that I just don’t understand. But there is a better way.

Let me start with a sample program.  This is just a ball tossed in the air – but with a pause button. Code here.

The magic happens in line 11.  When you put that scene.pause() in your program, you get a big “play” button in the lower right of your output window.  In this case, the program is paused before the calculations start so that the play button is there at the beginning.

Of course, you could have some calculations and then the pause button – it just depends on what you are trying to do.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.