用Python 3.5.1 Turtle绘制一个点



我应该使用创建的名为dot and Turtle的类绘制一个点。点是用代码创建的:

class Dot:
    def __repr__(self):
        return "Dot(" + repr(self.xcoord) + ", " + repr(self.ycoord) + ", " + repr(self.color) + ")"
    def __init__(self, xcoord, ycoord, color):
        self.xcoord = xcoord
        self.ycoord = ycoord
        self.color = color

我正在尝试创建的海龟使用:

import turtle
turtle.penup()
def draw():
    turtle1.goto(self.xcoord, self.ycoord)
    turtle1.dot(5, self.color)

我不知道我做错了什么,但乌龟只是坐在那里什么也不做。有人能帮我吗?

试试这个。

import turtle
class Dot:
    def __repr__(self):
        return "Dot(" + repr(self.xcoord) + ", " + repr(self.ycoord) + ", " + repr(self.color) + ")"
    def __init__(self, xcoord, ycoord, color):
        self.xcoord = xcoord
        self.ycoord = ycoord
        self.color = color
    def draw(self, turtle):
        turtle.goto(self.xcoord, self.ycoord)
        turtle.dot(5, self.color)
def main():
    turtle.penup()
    dot = Dot(10, 10, 'red')
    dot.draw(turtle)
    turtle.getscreen()._root.mainloop()
if __name__ == '__main__':
    main()

相关内容

最新更新