【问题标题】:Event mouse click in visual python可视化python中的事件鼠标单击
【发布时间】:2018-03-12 14:18:59
【问题描述】:

这是来自“vpython.org”教程的简单代码:

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

当我打印“ev”时,输出为 None,然后出现错误:

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

注意:我使用的是 Vpython7 和 Python3.6。

【问题讨论】:

  • 为什么scene.waitfor 返回None
  • 这是我的问题!
  • ...除了你没有问任何问题。文档是怎么说的?
  • 这段代码绝对来自文档,所以它说它不能返回 None。

标签: python python-3.x python-3.6 vpython


【解决方案1】:

此错误已在 VPython 7 中修复。您发布的示例有效。

对于 VPython 问题,最好在 VPython 论坛上发帖,那里有更多的 VPython 用户会看到你的问题,而不是在 stackoverflow 上发帖:

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

【讨论】:

  • 来自 vpython.org:这个模块会经常更新。您可以通过以下方式获取最新版本: pip install vpython --upgrade 或者如果使用 Anaconda,则 conda update -c vpython vpython
猜你喜欢
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 1970-01-01
  • 2014-05-29
  • 2011-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多