When I first started exploring Python’s Turtle module, polygons were one of the most fun and visually rewarding things to draw. Turtle graphics are a fantastic way to introduce programming concepts, especially for beginners who want to combine creativity with coding.
Drawing polygons with Python Turtle is not only an excellent exercise for understanding loops and angles, but it also opens doors to creating more complex graphics and designs.
In this article, I’ll walk you through different methods to draw polygons using Python Turtle. Whether you want to draw a simple triangle or a complex decagon, I’ll share practical tips and code snippets that you can easily follow.
How to Draw a Polygon Using Python Turtle
A polygon is a closed shape with straight sides. The key to drawing polygons with Turtle is understanding how to calculate the turning angle and how many sides your polygon has.
Read Draw a Shape in Python Using Turtle
Method 1: Draw a Polygon with a For Loop
This is the most straightforward method and my go-to approach for drawing polygons.
Here’s how it works:
- Decide the number of sides (e.g., 3 for triangle, 4 for square)
- Calculate the exterior angle as 360 divided by the number of sides
- Use a loop to move the turtle forward and then turn it by the calculated angle
import turtle
# Set up the screen
screen = turtle.Screen()
screen.title("Drawing Polygons with Python Turtle")
# Create a turtle object
pen = turtle.Turtle()
def draw_polygon(sides, length):
angle = 360 / sides
for _ in range(sides):
pen.forward(length)
pen.right(angle)
# Example: Draw a hexagon
draw_polygon(6, 100)
screen.mainloop()You can refer to the screenshot below to see the output.

Why I like this method:
It’s simple, reusable, and easy to tweak. You just change the number of sides and side lengths, and you get any polygon you want.
Check out Create a Snake Game in Python Using Turtle
Method 2: Draw Polygons with Recursive Functions
If you want to dive a little deeper, recursion can be a neat way to draw polygons. I often use this method when teaching students about recursion and how it applies to graphics.
Here’s a quick example:
import turtle
pen = turtle.Turtle()
def draw_polygon_recursive(sides, length, count=0):
if count == sides:
return
pen.forward(length)
pen.right(360 / sides)
draw_polygon_recursive(sides, length, count + 1)
draw_polygon_recursive(5, 100) # Draws a pentagon
turtle.done()You can refer to the screenshot below to see the output.

What I like about recursion here:
It’s a great way to combine programming concepts with graphics. Although it’s slightly more complex, it helps learners understand function calls and base cases.
Read Attach an Image in Turtle Python
Method 3: Draw Polygons with User Input
To make your polygons interactive, you can prompt users to enter the number of sides and length. This is especially useful in classroom settings or beginner workshops.
Example:
import turtle
pen = turtle.Turtle()
sides = int(input("Enter the number of sides for your polygon: "))
length = int(input("Enter the length of each side: "))
angle = 360 / sides
for _ in range(sides):
pen.forward(length)
pen.right(angle)
turtle.done()You can refer to the screenshot below to see the output.

Why this works well:
It engages users, making the learning experience more interactive. Plus, it’s a simple way to practice input handling in Python.
Method 4: Draw Colored Polygons
Adding color makes your polygons more visually appealing. I often encourage learners to experiment with colors to make their drawings stand out.
Here’s how you can fill a polygon with color:
import turtle
pen = turtle.Turtle()
def draw_colored_polygon(sides, length, color):
angle = 360 / sides
pen.fillcolor(color)
pen.begin_fill()
for _ in range(sides):
pen.forward(length)
pen.right(angle)
pen.end_fill()
draw_colored_polygon(8, 70, "blue") # Draws a blue octagon
turtle.done()What I like about this method:
It introduces beginners to the concept of filling shapes and working with colors, which is essential for creating more complex graphics.
Method 5: Draw Polygons with Varying Side Lengths
Sometimes, I like to challenge myself by drawing polygons where each side has a different length. This is a bit more advanced but great for understanding how Turtle moves.
Example:
import turtle
pen = turtle.Turtle()
sides = 5
lengths = [50, 100, 75, 120, 90] # Different side lengths
angle = 360 / sides
for length in lengths:
pen.forward(length)
pen.right(angle)
turtle.done()Why this is useful:
It breaks the monotony of regular polygons and introduces the idea that polygons don’t always have to be regular. This method is great for creative projects.
Check out Python Turtle Circle
Tips for Drawing Polygons with Python Turtle
- Start simple: Begin with triangles and squares before moving to polygons with more sides.
- Use functions: Encapsulate your polygon drawing logic in functions for better code reuse.
- Experiment with angles: Regular polygons have equal angles, but you can play with angles for creative shapes.
- Combine with loops: Use nested loops to create patterns of polygons, like flowers or stars.
- Control speed: Use
pen.speed()to speed up or slow down drawing, especially for complex polygons.
Drawing polygons with Python Turtle is a rewarding experience that combines programming logic with visual creativity. Whether you’re a teacher in the USA introducing kids to coding, a beginner learning Python, or an enthusiast looking to create graphics, mastering polygons is a great step forward.
By practicing these methods, you’ll not only improve your Python skills but also gain a solid foundation in geometry and programming concepts. Keep experimenting, and soon you’ll be creating intricate designs and patterns with ease.
If you have any questions or want to share your polygon creations, feel free to leave a comment below!
Other Python articles you may like:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.