pythonturtle-graphicspython-turtle

Python 3 Turtle - Hold 2 keys


So I have a turtle that moves left when 'a' is pressed.

def turtle_left():
    turtle.forward(-1)

turtle.listen()
turtle.onkeypress(turtle_left, 'a')

However, if I wanted another movement, for example pressing 'w' makes it move up, then it stops the turtle moving left. So what I'm asking is, can I have 2 keys being held at once to move the turtle, if possible I'd like to keep it in the turtle library - but maybe there is another key library that can help with this better.

Thank you!


Solution

  • Yes, you can do that without using any external library. I think this post is very similar to the given below.

    How to bind several key presses together in turtle graphics?

    You can make an array of events and then process it on the basis of total events in the list.