0

I am trying to move the object around the screen with the arrow keys. I have left and right how I want them, but when I am trying to go up it doesn't work how I want.

I tried to use player.left(90) then move forward but then I have to use the right arrow key to move up. I would prefer to not even have the object rotate 90deg

I just want to easily move the object around the window.

python

import turtle

window = turtle.Screen()
window.bgcolor('black')

player = turtle.Turtle()
player.shape('square')
player.color('white')
player.penup()

def move_left():
    player.color('light green')
    player.backward(10)
def move_right():
    player.color('light green')
    player.forward(10)
def move_up():
    player.color('light green')
    player.left(90)
    player.forward(10)

window.onkeypress(move_left, "Left")
window.onkeypress(move_right, "Right")
window.onkeypress(move_up, "Up")

window.listen()
turtle.done()
ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • 1
    Have a look at [`setheading()`](https://docs.python.org/3/library/turtle.html#turtle.setheading) – 001 Aug 17 '22 at 15:04
  • 2
    Does this answer your question? [How to move turtles in Python 3 with arrow keys](https://stackoverflow.com/questions/43449702/how-to-move-turtles-in-python-3-with-arrow-keys) – ggorlen Aug 17 '22 at 15:23

0 Answers0