如何正确实现VPython中的鼠标事件(语法错误无效)?

问题描述 投票:0回答:1

我尝试用鼠标拖动对象。因此,当我让它们用鼠标移动时,它们具有鼠标的新位置。我有两个问题。 1.在Glowscript中它运行但没有动作放开鼠标。当我点击它时我可以拖动它。但是当我想放开鼠标时,它继续拖动对象,直到我关闭程序。 2.我无法在Python编辑器中运行它,bc我得到此行的错误无效语法:scene.bind("mousedown", def():

整码:

drag=False
R = vec(0,0,0)
scene.bind("mousedown", def():
    global drag
    drag=True

    scende.bind("mouseup", def():
        global drag
        drag=False
    )
)

while (True):

    rate(framerate)  
    if drag:
        R=scene.mouse.pos
        e.pos=R
    if running

当然,这段代码中缺少一些东西。在它上面我生成常量和对象,在if running下函数是。这是必须存在错误的拖动事件的代码。

python mouseevent vpython
1个回答
0
投票
drag=False
R = vec(0,0,0)
scene.bind("mousedown", def():
    global drag
    drag=True

    scene.bind("mouseup", def():
        global drag
        drag=False
    )
)

while (True):

    rate(framerate)  
    if drag:
        R=scene.mouse.pos
        e.pos=R
    if running
© www.soinside.com 2019 - 2024. All rights reserved.