Fundamentals 5 min read

Explore Python Turtle: Draw Shapes, Change Pens, and Fill Colors

This guide introduces Python’s Turtle graphics library, explaining its screen and turtle concepts, and demonstrates how to draw rectangles, stars, circles, and arcs, while showing how to change pen attributes and apply fill colors, providing visual examples for beginners and intermediate learners.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Explore Python Turtle: Draw Shapes, Change Pens, and Fill Colors

What is Turtle?

Turtle (also known as turtle graphics) is a Python drawing library that simulates a small turtle moving on the screen; the path it crawls forms the drawn graphics.

Basic Concepts

There are two essential concepts in Turtle:

Screen: The drawing area where you can set size and background color. The coordinate origin is at the center of the screen.

Turtle (pen): The drawing tool created from the Turtle class. It has properties such as color, line width, position, and direction.

Drawing a Rectangle

The following example shows how to draw a rectangle using Turtle.

Rectangle example
Rectangle example

Code (shown as an image):

Rectangle code
Rectangle code

Changing Pen Attributes

You can modify the pen’s color, width, and other attributes.

Change pen
Change pen

Setting the Pen

Setting the pen includes choosing its shape, size, and style.

Set pen
Set pen

Filling Colors

Use begin_fill() and end_fill() to fill shapes with color.

Fill color
Fill color

Drawing Basic Shapes

Turtle can draw lines, arcs, and text, which can be combined to create various polygons.

Basic shapes
Basic shapes

Drawing a Star

The example below demonstrates how to draw a five‑pointed star.

Star drawing
Star drawing

Drawing Circles and Arcs

Since Turtle can draw arcs, it can also draw circles. The following example shows both.

Circle and arc
Circle and arc

Code (shown as an image):

Circle and arc code
Circle and arc code

This article is excerpted from the book Learn Python with Comics 2: Fun, Informative, Playful, and Useful (Full‑Color Advanced Edition) , which provides a comic‑style approach to teaching Python concepts.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GraphicsturtledrawingBeginner
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.