DEV Community

Cover image for Python & Turtle. Drawing in the jungle
petercour
petercour

Posted on

Python & Turtle. Drawing in the jungle

Learn Python doesn't have to be boring. You may be stuck in the command line trying all kinds of codes. Why not have some fun learning?

The module turtle lets you draw in the Python programming language.
Officially it's is a popular way for introducing programming to kids, but even for adults its fun :)

Turtle example

Turtle draws on the screen. It can move coordinate and change colors. In the example below the olympic games logo is drawn

#!/usr/bin/python3
# https://pythonprogramminglanguage.com
import turtle
import time

turtle.setworldcoordinates(-250, -250, 640, 480)
turtle.width(20)

turtle.circle(60)
turtle.penup()
turtle.forward(140)
turtle.pendown()
turtle.color("red")
turtle.circle(60)
turtle.penup()
turtle.forward(140)
turtle.pendown()
turtle.color("yellow")
turtle.circle(60)
turtle.penup()
turtle.goto(210, -50)  
turtle.pendown()
turtle.color("blue")
turtle.circle(60)
turtle.penup()
turtle.goto(60, -50)
turtle.pendown()
turtle.color("green")
turtle.circle(60)

time.sleep(5)

Outputs:

Python resources:

Top comments (0)