Open In App

Draw Heart Using Turtle Graphics in Python

Last Updated : 17 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Python's Turtle Graphics module provides a simple way to create drawings and shapes using a virtual pen (called a "turtle") that can move across the screen. In this tutorial, we will learn how to draw a heart shape using Turtle Graphics and customize it with colors and text. Before proceeding, you should have a basic understanding of Turtle Programming in Python. You can install the Turtle module (if not already installed) using:

pip install PythonTurtle

However, the Turtle module is built-in with Python, so no additional installation is usually required.

Step-by-Step Approach

  • Import Turtle: Load the Turtle module in Python.
  • Create a Turtle object: This acts as a pen for drawing.
  • Define a function for the curve: The heart consists of two smooth curves.
  • Draw the heart shape: Combine straight lines and curves to form the heart.
  • Display text inside the heart: Add a message using Turtle’s write() function.
  • Execute the drawing: Call the functions to create the final output.

Python code

python
import turtle

pen = turtle.Turtle()

# Defining a method to draw curve
def curve():
    for i in range(200):

        pen.right(1)
        pen.forward(1)

# Defining method to draw a full heart
def heart():

    pen.fillcolor('red')
    pen.begin_fill()
    pen.left(140)
    pen.forward(113)
    curve()
    pen.left(120)
    curve()
    pen.forward(112)
    pen.end_fill()

# Defining method to write text
def txt():
    
    pen.up()
    pen.setpos(-68, 95)
    pen.down()
    pen.color('lightgreen')

    pen.write("GeeksForGeeks", font=("Verdana", 12, "bold"))

heart()
txt()
pen.ht()

Output:

turtle-heart

Explanation:

  • Left Side: Turn 140° left, move forward to form the straight edge.
  • Left Curve: Loop 200 times, moving forward and turning 1° right in each step.
  • Right Curve: Turn 120° left, repeat the curve function.
  • Right Side: Move forward to complete the heart shape.
  • Fill Color: Start filling before drawing and stop after completion.
  • Add Text: Lift the pen (pen.up()), move to position, write text with pen.write().
  • Hide Turtle: Use pen.ht() to remove the cursor after drawing.

Related Articles:


Next Article
Article Tags :
Practice Tags :

Similar Reads