Lesson 14: Controlling the turtle

posted Jan 28, 2020, 8:03 AM by Attila Lengyel
import turtle as t
john = t.Turtle()

john.shape("turtle")
john.fillcolor("blue")
john.pencolor("blue")
screen = t.Screen()

def move_forward():
john.pencolor("blue")
john.forward(10)
def move_backward():
john.pencolor("white")
john.backward(10)
def turn_right():
john.right(10)
def turn_left():
john.left(10)
def clear_screen():
john.clear()
def start_draw():
john.pendown()
def stop_draw():
john.penup()

screen.onkey(move_forward, "Up")
screen.onkey(move_backward, "Down")
screen.onkey(turn_right, "Right")
screen.onkey(turn_left, "Left")
screen.onkey(clear_screen, "c")
screen.onkey(stop_draw, "u")
screen.onkey(start_draw, "d")

screen.listen()

Comments