Download code to move turtle with arrow keys Download script for turtle move in python with arrow keys

Share

Download code to move turtle with arrow keys Download script for turtle move in python with arrow keys free script Download python turtle move with arrow keys

 

Download Script – python move object with arrow keys 

move turtle object using keyboard in python

from turtle import Turtle, Screen

wn = Screen()
wn.bgcolor('yellow')

spaceship = Turtle()
spaceship.color('red')
spaceship.penup()

speed = 0.8

def travel():
    spaceship.forward(speed)
    wn.ontimer(travel, 1)

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

wn.listen()

travel()

wn.mainloop()

Share
Related  write a code in HTML for form that send input text string from the same page

Leave a Reply

Your email address will not be published. Required fields are marked *