如何使用“getMouse()&getMouseNow()”,哪个文件包含这些函数?

2024-06-09 05:03:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我用了泽尔的”图形.py“文件。我用Thonny。我想要 使用函数“getMouse()&getMouseNow()”,但出现以下消息。我该怎么办?帮助我!在

代码:

from graphics import *

def draw():
    win = GraphWin("My Circle", 500, 500)
    circle = Circle(Point(150,150), 50)
    circle.draw(win)
    p = win.getMouse()
    x = p.x
    y = p.y
    circle.moveTo(x,y)

draw()

输出:

创建一个具有上述尺寸的窗口,并在其中创建一个圆。 点击窗口后。。。在

^{pr2}$

Tags: 文件函数代码frompy图形消息win
2条回答

没有moveTo()方法,您也不需要它,move()方法应该按照您想要的方式进行,如果您相对于对象的中心位置进行移动:

from graphics import *

win = GraphWin("My Circle", 500, 500)

# ...

circle = Circle(Point(150, 150), 50)
circle.draw(win)

# ...

while True:
    point = win.getMouse()
    center = circle.getCenter()
    circle.move(point.x - center.x, point.y - center.y)

函数的作用是:返回一个Point(http://mcsp.wartburg.edu/zelle/python/graphics.py)的实例,从中可以提取x和y

p = win.getMouse()
x = p.x
y = p.y

我希望这有帮助:)

相关问题 更多 >