2016-04-07 44 views
0

我應該使用一個名爲Dot和Turtle的創建類來繪製一個點。用Python繪製一個點3.5.1 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) 

我不知道我在做什麼錯,但烏龜只是坐在那裏,什麼也沒做。誰能幫我?

+0

你忘了叫'draw()'? – zondo

回答

0

試試這個。

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()