I am a relative newbie in Python (but have decades experience programming in many languages). When I execute the following code (from the mouse-events tutorial) the code "works", but I see the following in the shell (v3.6.1) window:
Traceback (most recent call last):
File "D:\Projects\Python\Examples\mouse_events.py", line 7, in <module>
if scene.mouse.events:
AttributeError: 'Mouse' object has no attribute 'events'
from vpython import *
scene.range = 5 # fixed size, no autoscaling
ball = sphere(pos=vector(-3,0,0), color=color.cyan)
cube = box(pos=vector(+3,0,0), size=vector(2,2,2), color=color.red)
pick = None # no object picked out of the scene yet
while True:
if scene.mouse.events:
m1 = scene.mouse.getevent() # get event
if m1.drag and m1.pick == ball: # if touched ball
drag_pos = m1.pickpos # where on the ball
pick = m1.pick # pick now true (not None)
elif m1.drop: # released at end of drag
pick = None # end dragging (None is false)
if pick:
# project onto xy plane, even if scene rotated:
new_pos = scene.mouse.project(normal=vector(0,0,1))
if new_pos != drag_pos: # if mouse has moved
# offset for where the ball was clicked:
pick.pos += new_pos - drag_pos
drag_pos = new_pos # update drag position
The behavior currently is unacceptable because when I migrate the relevant pieces to my own program, it halts because of this error. (I am trying to use the mouse or the keyboard to halt a continuously running program.) This from the VPython shell V3.6.1
Thanks in advance.