python turtle怎么用变量_Python Turtle绘图指定变量时出现问题
幾小時后我有一個作業要交,我不知道該做什么。
我使用的是python3。在
我一直試著運行代碼,但是我出錯了。在這一點上,我想我應該尋求幫助。在
提前謝謝你!在import turtle
import random
class myRectangle:
def __var__(self):
self.__x
self.__y
self.__width
self.__height
self.__color
def __init__(self, x, y, width, height, color):
self.__x = x
self.__y = y
self.__width = width
self.__height = height
self.__color = color
def getX(self):
return self.__x
def setX(self, x):
self.__x = x
def getY(self):
return self.__y
def setY(self, y):
self.__y = y
def getWidth(self):
return self.__width
def setWidth(self, width):
self.__width = width
def getHeight(self):
return self.__height
def setHeight(self, height):
self.__height = height
def getColor(self):
return self.__color
def setColor(self, color):
self.__color = color
def draw(self, turtle):
turtle.penup()
turtle.goto(self.getX(), self.getY())
turtle.heading(0)
turtle.pencolor("blue")
turtle.pendown()
turtle.begin_fill()
turtle.forward(self.__width())
turtle.left(90)
turtle.forward(self.__height())
turtle.left(90)
turtle.forward(self.__width())
turtle.left(90)
turtle.forward(self.__height())
turtle.left(90)
turtle.end_fill()
def main():
wn = turtle.TurtleScreen
mr = myRectangle
phil = turtle.Turtle()
macie = turtle.Turtle()
sashi = turtle.Turtle()
roxie = turtle.Turtle()
darla = turtle.Turtle()
sammy = turtle.Turtle()
phil.pencolor("blue")
phil.pensize(7)
listofcolors = ("blue", "red", "yellow", "orange", "pink", "green")
c = random.choice(listofcolors)
xy = random.randrange(-200, 201)
wh = random.randrange(1, 151)
for i in [phil, macie, sashi, roxie, darla, sammy]:
mr.setColor(c)
mr.setX(xy)
mr.setY(xy)
mr.setWidth(wh)
mr.setHeight(wh)
main()
錯誤:
^{pr2}$
總結
以上是生活随笔為你收集整理的python turtle怎么用变量_Python Turtle绘图指定变量时出现问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查看pod网络范围_可用网络的ip地址范
- 下一篇: python 树_Python树的概念