python left and right arrow key event not working
Question: I am new to Python and trying to create a turtle shape and once the user
clicks the left or right arrow keys on keyboard the shape should move in that
direction, however nothing is happening.

I am trying to move the player using the left and right arrow keys, buts its
not working please help and advice.

    
    
     #Create the player turtle
        player = turtle.Turtle()
        player.color("blue")
        player.shape("triangle")
        player.penup()
        player.speed(0)
        player.setposition(0, -235)
        player.setheading(90)
    
        playerspeed = 15
    
    
        #Move the player Left and Right
        def move_left():
            x = player.xcor()
            x -= playerspeed
            if x < -200:
                x = - 200
            player.setx(x)
    
        def move_right():
            x = player.xcor()
            x +- playerspeed
            if x < -200:
                x = - 280
            player.setx(x)
    
    #Create Keyboard Bindings
        turtle.listen()
        turtle.onkey(move_left,"Left")
        turtle.onkey(move_right, "Right")
    


Answer: You need to call `turtle.mainloop()` at the end of the script, see
<https://docs.python.org/2/library/turtle.html#turtle.mainloop>

This works (it shows a blue triangle turtle that moves left or right depending
in the cursor keys pressed; it includes the fix suggested by
[@zondo](http://stackoverflow.com/users/5827958/zondo)):

    
    
    import turtle
    
    #Create the player turtle
    player = turtle.Turtle()
    player.color("blue")
    player.shape("triangle")
    player.penup()
    player.speed(0)
    player.setposition(0, -235)
    player.setheading(90)
    
    playerspeed = 15
    
    
    #Move the player Left and Right
    def move_left():
        x = player.xcor()
        x -= playerspeed
        if x < -200:
            x = - 200
        player.setx(x)
    
    def move_right():
        x = player.xcor()
        x += playerspeed
        if x < -200:
            x = - 280
        player.setx(x)
    
    #Create Keyboard Bindings
    turtle.listen()
    turtle.onkey(move_left, "Left")
    turtle.onkey(move_right, "Right")
    
    #Start the main loop
    turtle.mainloop()
    

