screen onkey python

Solutions on MaxInterview for screen onkey python by the best coders in the world

showing results for - "screen onkey python"
Lia
19 Aug 2020
1from turtle import Turtle, Screen
2
3screen = Screen()
4screen.setup(1200, 500)
5
6# Ground
7
8ground = Turtle()
9ground.speed('fastest')
10
11ground.penup()
12ground.goto(-1000, -200)
13ground.pendown()
14ground.forward(2000)
15
16# Player
17
18player = Turtle()
19player.speed('fastest')
20
21PlayerX = -600
22
23def moveX():
24    global PlayerX
25
26    screen.onkeypress(None, "w")  # disable handler in handler
27    player.clear()
28    player.penup()
29    player.goto(PlayerX, -99)
30    player.pendown()
31    player.color("Slate Gray")
32    player.begin_fill()
33    player.circle(-50)
34    player.end_fill()
35
36    PlayerX -= 1
37
38    screen.onkeypress(moveX, "w")  # reenable handler
39
40screen.listen()
41
42moveX()
43
44screen.mainloop()  # change import & use turtle.mainloop() if Python 2