Horje
screen.onkey python Code Example
screen.onkey python
from turtle import Turtle, Screen

screen = Screen()
screen.setup(1200, 500)

# Ground

ground = Turtle()
ground.speed('fastest')

ground.penup()
ground.goto(-1000, -200)
ground.pendown()
ground.forward(2000)

# Player

player = Turtle()
player.speed('fastest')

PlayerX = -600

def moveX():
    global PlayerX

    screen.onkeypress(None, "w")  # disable handler in handler
    player.clear()
    player.penup()
    player.goto(PlayerX, -99)
    player.pendown()
    player.color("Slate Gray")
    player.begin_fill()
    player.circle(-50)
    player.end_fill()

    PlayerX -= 1

    screen.onkeypress(moveX, "w")  # reenable handler

screen.listen()

moveX()

screen.mainloop()  # change import & use turtle.mainloop() if Python 2




Python

Related
unique combinations in python Code Example unique combinations in python Code Example
solve system of linear equations numpy Code Example solve system of linear equations numpy Code Example
get information about dataframe Code Example get information about dataframe Code Example
while loop odd numbers python Code Example while loop odd numbers python Code Example
sum of positive numbers in array with negative python Code Example sum of positive numbers in array with negative python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
6