gpt4 book ai didi

python - 属性错误: 'function' object has no attribute 'move'

转载 作者:太空宇宙 更新时间:2023-11-03 14:25:14 25 4
gpt4 key购买 nike

我对使用 python 非常陌生,并试图开始我的最终项目,以介绍计算类(class)。我正在使用Zelle graphics尝试创建 python 游戏的模块。我已经使用图形模块创建了一张脸,我想克隆这张脸并将克隆版本向右移动 50 个空格。我导入了时间来移动对象。

这是有问题的代码:

from graphics import *

导入时间

def main():
win = GraphWin("猜猜面孔", 1000, 500)
win.yUp()
win.setBackground(color_rgb(20, 20, 20))

def robotFaces():
robot1 = Rectangle(Point(25, 350), Point(100, 425))
robot1.setOutline(color_rgb(0, 0, 0))
robot1.setFill(color_rgb(180, 180, 180))
robot1.draw(win)
r1eye1 = Rectangle(Point(35, 390), Point(55, 415))
r1eye1.setOutline(color_rgb(0, 0, 0))
r1eye1.setFill(color_rgb(255, 255, 255))
r1eye1.draw(win)
r1eye2 = Rectangle(Point(70, 390), Point(90, 415))
r1eye2.setOutline(color_rgb(0, 0, 0))
r1eye2.setFill(color_rgb(255, 255, 255))
r1eye2.draw(win)
r1pupil1 = Rectangle(Point(42, 390), Point(48, 408))
r1pupil1.setFill(color_rgb(0, 0, 0))
r1pupil1.draw(win)
r1pupil2 = Rectangle(Point(77, 390), Point(83, 408))
r1pupil2.setFill(color_rgb(0, 0, 0))
r1pupil2.draw(win)
r1mouth = Polygon(Point(35, 360),
Point(90, 360),
Point(90, 370),
Point(85, 370),
Point(85, 365),
Point(40, 365),
Point(40, 370),
Point(35, 370))
r1mouth.setFill(color_rgb(255, 255, 255))
r1mouth.setOutline(color_rgb(0, 0, 0))
r1mouth.draw(win)

robot2 = robot1.clone
robot2.move(50, 0)
robot2.draw(win)
r2eye1 = r1eye1.clone
r2eye1.move(50, 0)
r2eye1.draw(win)
r2eye2 = r1eye2.clone
r2eye2.move(50, 0)
r2eye2.draw(win)
r2pupil1 = r1pupil1.clone
r2pupil1.move(50, 0)
r2pupil1.draw(win)
r2pupil2 = r1pupil2.clone
r2pupil2.move(50, 0)
r2pupil2.draw(win)
r2mouth = r1mouth.clone
r2mouth.move(50, 0)
r2mouth.draw(win)

robotFaces()

win.getMouse()
win.promptClose(win.getWidth()/2, 10)

main()

我预计会有第二个机器人脸,位于原始脸右侧 50 个空格处。实际发生的是我收到此属性错误:

AttributeError: 'function' object has no attribute 'move'

我还需要做些什么才能使物体可移动吗?

最佳答案

您没有调用克隆方法。

robot2 = robot1.clone()

将来,请将您的代码减少到演示问题所需的最少代码,并发布完整的回溯。

关于python - 属性错误: 'function' object has no attribute 'move' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47682677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com