Search code examples
pythonpython-3.xpython-3.6vpython

Event mouse click in visual python


This is a simple code from "vpython.org" tutorial:

from vpython import *
scene = canvas(title='Rubic solver!',
     width=800, height=600,
     center=vector(5,0,0), background=color.white,userzoom=0,userspin=0,userpan=0)
box()
while True: 
    ev = scene.waitfor('mousedown mouseup')
    print(ev)
    if ev.event == 'mousedown':
        print('You pressed the mouse button')
    else:
        print('You released the mouse button')
    print(ev.pos) # the position of the mouse

and when I print "ev" the output is None and then there is an error:

    if ev.event == 'mousedown':
AttributeError: 'NoneType' object has no attribute 'event'

note: I'm using Vpython7 and Python3.6 .


Solution

  • This bug has been fixed in VPython 7. The example you posted works.

    For VPython questions it's better to post to the VPython forum, where there are many more VPython users who will see your question than if you post to stackoverflow:

    https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users