1

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

这是有问题的代码:

from graphics import *

import time

def main(): win = GraphWin("Guess the Faces", 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:“功能”对象没有属性“移动”

我还需要做些什么来使对象可移动吗?

4

1 回答 1

1

您没有调用 clone 方法。

robot2 = robot1.clone()

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

于 2017-12-06T20:12:59.867 回答