Pause on click

24 views
Skip to first unread message

Matthew Odegard

unread,
Nov 14, 2017, 10:38:12 AM11/14/17
to VPython-users
Hey guys how do you pause a program on mouse click? I have an animation running and I want to have it pause when the mouse is clicked. Any help would be awesome!

-Matthew

Bruce Sherwood

unread,
Nov 14, 2017, 11:20:54 AM11/14/17
to VPython-users
Here is one way:

b = box(pos=vec(-10,0,0))
run = True

def handle(c):
    global run
    run = c.checked

checkbox(bind=handle, text='Run', checked=True)

while True:
    rate(10)
    if run:
        b.pos.x += 0.1


Bruce Sherwood

unread,
Nov 14, 2017, 11:23:31 AM11/14/17
to VPython-users
And here's a different way:

b = box(pos=vec(-10,0,0))
scene.caption = 'Click to toggle between run and pause'
run = True

def handle():
    global run
    run = not run

scene.bind('click', handle)
Reply all
Reply to author
Forward
0 new messages