我的define语句只运行一次

时间:2017-09-23 21:40:15

标签: python python-3.x

在我的代码在屏幕上打印一个点后,它不会再次运行。这是我关闭龟屏后在终端告诉我的内容:

Traceback (most recent call last):
  File "/Users/Benjamin/Desktop/Space Digital Scene.py", line 33, in <module>
    star(size, x, y, color)
  File "/Users/Benjamin/Desktop/Space Digital Scene.py", line 12, in star
    drawer.begin_fill()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/turtle.py", line 3322, in begin_fill
    self._fillitem = self.screen._createpoly()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/turtle.py", line 497, in _createpoly
    return self.cv.create_polygon((0, 0, 0, 0, 0, 0), fill="", outline="")
  File "<string>", line 1, in create_polygon
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 2492, in create_polygon
    return self._create('polygon', args, kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 2474, in _create
    *(args + self._options(cnf, kw))))
_tkinter.TclError: invalid command name ".!canvas"

我的代码是

import turtle
import random

def star(size, X, Y, color):
    drawer.goto(X, Y)
    drawer.color(color)
    drawer.begin_fill()
    drawer.circle(size)
    drawer.end_fill()

hex = ["blue","red","yellow","white"]

screen = turtle.Screen()
turtle.bgcolor("black")
drawer = turtle.Turtle()
drawer.speed("fastest")

x = random.randint(-300,301)
y = random.randint(-300,301)
color = random.choice(hex)
size = random.randint(1,6)

a = 1
b = 100

while True:
    if a <= b:
        star(size, x, y, color)
        drawer.hideturtle()
        a + 1
        continue
    else:
        break

screen.mainloop()

1 个答案:

答案 0 :(得分:1)

您必须分配新的> seqle(year) Run Length Encoding lengths: int [1:3] 4 1 4 values : num [1:3] 2000 2005 2007 或使用a并在a += 1循环中移动一些行以便每次都执行它们:

while
相关问题