This is my code:
from turtle import Turtle, Screen
wn = Screen()
wn.bgcolor('lightblue')
spaceship = Turtle()
spaceship.color('red')
spaceship.penup()
speed = 1
def travel():
spaceship.forward(speed)
wn.ontimer(travel, 10)
wn.onkey(lambda: spaceship.setheading(90), 'Up')
wn.onkey(lambda: spaceship.setheading(180), 'Left')
wn.onkey(lambda: spaceship.setheading(0), 'Right')
wn.onkey(lambda: spaceship.setheading(270), 'Down')
while True:
spaceship.forward(speed)
if spaceship.xcor() > 500:
spaceship.goto (-500,0)
elif spaceship.ycor() > 500:
spaceship.goto(0,-500)
wn.listen()
travel()
wn.mainloop()
I'm trying to get my keyboard movement to work but after i put the while true codes in they stopped working and in try to get them to work to have the turtle move.