Lesson 18: Events handling with Turtle

posted Apr 17, 2019, 8:00 AM by Attila Lengyel
import turtle
screen = turtle.Screen()
turtle.shape("turtle")
turtle.fillcolor("blue")
turtle.pencolor("blue")
speed = 10
turn = 10

def f():
turtle.forward(speed)
turtle.fillcolor("red")
turtle.pencolor("red")

def b():
turtle.backward(speed)
turtle.fillcolor("blue")
turtle.pencolor("blue")

def l():
turtle.left(turn)

def r():
turtle.right(turn)

def c():
turtle.clear()

turtle.speed(0)

screen.onkey(f, "Up")
screen.onkey(b, "Down")
screen.onkey(l, "Left")
screen.onkey(r, "Right")
screen.onkey(c, "c")
screen.listen()

Comments