Я пытался сделать игру, похожую на змею, используя графику черепахи. Добавил строчку wn.update, но каждый раз пишет en error, а если убрать, то просто вылетает. Кто-нибудь знает, почему?
Я довольно новичок в питоне, поэтому у меня может быть действительно глупая ошибка
import turtle
import random
score = 0
def go_up():
if cat.direction != "down":
cat.direction = "up"
def go_down():
if cat.direction != "up":
cat.direction = "down"
def go_left():
if cat.direction != "right":
cat.direction = "left"
def go_right():
if cat.direction != "left":
cat.direction = "right"
def move():
if cat.direction == "up":
y = cat.ycor()
cat.sety(y + 20)
if cat.direction == "down":
y = cat.ycor()
cat.sety(y - 20)
if cat.direction == "left":
x = cat.xcor()
cat.setx(x - 20)
if cat.direction == "right":
x = cat.xcor()
cat.setx(x + 20)
wn = turtle.Screen()
wn.setup(width =600,height= 600)
wn.tracer(0)
mouse=turtle.Turtle()
mouse.penup()
mouse.goto(0,100)
cat = turtle.Turtle()
cat.penup()
while True:
wn.update()
if cat.distance(mouse) < 20:
x = random.randint(0, 500)
y = random.randint(0, 500)
mouse.goto(x, y)
wn.onkeypress(go_up, "w")
wn.onkeypress(go_down, "s")
wn.onkeypress(go_left, "a")
wn.onkeypress(go_right, "d")
wn.listen()
wn.mainloop()
File "C:/Users/avner/PycharmProjects/CatAndMouse/main.py", line 52, in <module> wn.update() File "C:\Users\avner\AppData\Local\Programs\Python\Python38\lib\turtle.py", line 1304, in update t._update_data() File "C:\Users\avner\AppData\Local\Programs\Python\Python38\lib\turtle.py", line 2647, in _update_data self.screen._incrementudc() File "C:\Users\avner\AppData\Local\Programs\Python\Python38\lib\turtle.py", line 1293, in _incrementudc raise Terminator turtle.Terminator
- person noobpythonstudent   schedule 06.05.2021