Escriu per cercar…

Turtle

The turtle module provides a visual and intuitive way to introduce programming concepts through a simple, interactive graphics interface.

Aquesta pàgina encara no s'ha traduït — es mostra en l'idioma original:English

Introduction

The turtle module is a classic and effective way to introduce programming concepts through interactive graphics. It provides immediate visual feedback, making it ideal for beginners to explore how software works.

Originally developed as an educational tool for the classroom, turtle graphics offers a simple way to generate graphical output without the complexity of external libraries. Whether you’re teaching programming to children or just need a quick way to draw something on the screen, turtle is a joy to use due to its minimal overhead and intuitive commands.

Getting started

The turtle module exposes its basic functionality as a set of functions.

Start a new interactive Python session:

shell
uv run python

Basic drawing

Imagine a robotic turtle starting at the center of the screen (position (0, 0) in the x-y plane).

Import all the objects from the turtle module:

python
from turtle import *

Send the turtle forward 100 steps:

python
forward(100)

You should see a new window appear on your display with a line drawn by the turtle, heading East.

Next, we can change the direction of the turtle. Let’s make it turn 120 degrees to the left (counter-clockwise):

python
left(120)

Estàs llegint una vista prèvia.

Inicia sessió per llegir l'article complet. Qualsevol compte obre 4 articles gratuïts al mes; l'alumnat i el professorat llegeixen les pàgines del seu curs sense límit.

Inicia sessió