我使用了 Zelle 的“graphics.py”文件。我用的是松尼。我想 使用函数“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()
输出:
创建一个以上尺寸的窗口并在其中创建一个圆。 点击进入窗口后...
Traceback (most recent call last):
File "C:\Users\Shivam\Documents\Python\Mouse.py", line 13, in <module>
draw()
File "C:\Users\Shivam\Documents\Python\Mouse.py", line 10, in draw
m = Circle.moveTo(x,y)
AttributeError: type object 'Circle' has no attribute 'moveTo'
请您参考如下方法:
getMouse() 函数返回 Point ( http://mcsp.wartburg.edu/zelle/python/graphics.py ) 的实例,您可以从中提取 x 和 y。您可以使用例如:
p = win.getMouse()
x = p.x
y = p.y
希望对你有帮助:)
