Say I Love You using a Python Code

A romantic scene with a couple sitting on a bench, expressing love to each other.

Introduction

When it comes to expressing loveā¤ļø, there are countless ways to do so. From verbal declarations to grand gestures, the possibilities are endless. But have you ever thought about expressing your love using a Python program? Thatā€™s right, with a little bit of Python, you can create a program that tells someone how much you love him/her.

In this tutorial, I will show you how you can say I Love You using a Python Program. We will implement this idea using the Python Turtle module. So, come along as we discover the beauty of coding, where each line speaks not just as a command but whispers affection in the language of Python.

Requirements and Installations

If Python isnā€™t already a resident on your system, fear not! Grab the latest version from their website (https://www.python.org/). Once settled, remember to install the Turtle module and pygame library using the command below.

pip install PythonTurtle
pip install pygame

Import the Modules

Create a separate folder named ā€˜I-Love-You-in-Pythonā€˜ for this topic and declare a Python file with the name ILoveYou.py. Now start writing your code by importing these modules.

import turtle
import time
from pygame import mixer

Initialize Turtle Module

Letā€™s initialize the Turtle module.

t = turtle.Turtle()

Initialize the PyGame Mixer

Now, letā€™s initiate the PyGame mixer to play background music. Download the .mp3 file using the ā€˜Downloadā€™ button below and place it within the ā€˜I-Love-You-in-Pythonā€™ folder.

mixer.pre_init(frequency=48000, size=-16, channels=2, buffer=512)
mixer.init()
mixer.music.load("memories.mp3")

Set the Background Window

Letā€™s set the Turtle window settings, including background color and size. Iā€™ve chosen a black background, but feel free to customize it to your preference. The window size Iā€™ve set is 800Ɨ700, but you can modify it according to your preferences.

window = turtle.Screen()
window.bgcolor('black')
window.screensize(800, 700)
window.setup(width=1.0, height=1.0, startx=None, starty=None)

Play the Music

Letā€™s start playing the music you have added just one step before.

mixer.music.play()

Draw the ā€˜Iā€™ Letter

To begin, weā€™ll initiate the drawing with the letter ā€˜I.ā€™ Itā€™s a pretty straightforward process. In this step, we guide our Turtle using various numerical commands for moving forward, backward, left, right, and turning around at different angles.

t.penup()
t.goto(-80,300)
time.sleep(1)
t.pendown()
t.shapesize(1,2,1)

# 'I'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)

t.begin_fill()

t.fd(160)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(60)
t.lt(90)
# Height of 'I'
t.fd(140)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(160)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(140)
t.left(90)
t.fd(60)
t.rt(90)
t.fd(25)

t.end_fill()
# End of 'I'

Draw the ā€˜Loveā€™ Word

Hopefully, your code is successfully creating the ā€˜Iā€™ letter. Now, letā€™s proceed to write the entire word ā€˜Love.ā€™ The logic remains the same as before. So, letā€™s express your love through this segment of code.

t.penup()
t.goto(-550,-20)
t.pendown()


# Word: 'Love'
# 'L'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=2)
t.begin_fill()

t.rt(90)
t.fd(25)
t.rt(90)
t.fd(165)
t.lt(90)
t.fd(115)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(140)
t.rt(90)
t.fd(190)
t.rt(90)

t.end_fill()
# End of 'L'

t.penup()
t.fd(140)

# Gap between 'L' and 'O'
t.fd(70)

# 'O'
t.pen(pencolor="white",fillcolor="cyan", pensize=3, speed=8)
t.begin_fill()

t.rt(90)
t.fd(190)
t.lt(90)
t.pendown()
t.circle(60)
t.lt(90)
t.penup()
t.fd(20)
t.rt(90)
t.pendown()
t.circle(40)
t.rt(90)
t.penup()
t.fd(20)
t.lt(90)

t.end_fill()
# End of 'O'

# Gap between 'O' and 'V'
t.fd(100)
t.pendown()

# 'V'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(100)
t.fd(120)
t.rt(100)
t.fd(20)
t.rt(80)
t.fd(100)
t.lt(80)
t.fd(20)
t.lt(80)
t.fd(100)
t.rt(80)
t.fd(20)
t.rt(100)
t.fd(120)
t.rt(80)
t.fd(50)
t.lt(180)

t.end_fill()
# End of 'V'

t.penup()
# Gap between 'V' and 'E'
t.fd(100)
t.pendown()

# 'E'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(90)
t.fd(120)
t.rt(90)
t.fd(80)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(30)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(30)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(80)

t.end_fill()
# End of 'E'
# End of 'Love'

Draw the ā€˜Youā€™ Word

Weā€™ve effectively showcased ā€˜Iā€™ and ā€˜Loveā€™ using our Python program. Letā€™s finalize both this sentence and your feelings towards him/her. This part of the code will draw the word ā€˜Youā€™ on the screen.

# Start of 'You'
# 'Y'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=2)
t.begin_fill()

t.lt(90)
t.fd(50)
t.lt(30)
t.fd(80)
t.rt(120)
t.fd(20)
t.rt(60)
t.fd(60)
t.lt(180)
t.rt(60)
t.fd(60)
t.rt(60)
t.fd(20)
t.rt(120)
t.fd(80)
t.lt(30)
t.fd(50)
t.rt(90)
t.fd(20)
t.rt(180)

t.end_fill()
# End of 'Y'

t.penup()
# Gap between 'Y' and 'O'
t.fd(120)
t.pendown()

# 'O'
t.pen(pencolor="white",fillcolor="cyan", pensize=3, speed=8)
t.begin_fill()

t.circle(60)
t.lt(90)
t.penup()
t.fd(20)
t.pendown()
t.rt(90)
t.circle(40)
t.rt(90)
t.penup()
t.fd(20)
t.lt(90)

t.end_fill()
# End of 'O'

# Gap between 'O' and 'U'
t.fd(100)
t.circle(60, extent=60)
t.pendown()

# 'U'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(30)
# Height of 'U'
t.fd(85)
t.lt(90)
t.fd(20)
t.lt(90)
t.fd(70)
t.circle(-20, extent=180)
t.fd(70)
t.lt(90)
t.fd(20)
t.lt(90)
t.fd(85)
t.circle(40, extent=180)

t.end_fill()
# End of 'U'
# End of 'You'

t.penup()
# t.goto(300,130)
t.rt(180)
t.fd(35)
t.lt(90)
t.fd(140)
t.lt(90)
t.pendown()

Define the `curve` Function

Our program flawlessly illustrates ā€˜I Love You.ā€™ While everything is already perfect, imagine how it would look with the addition of a love sign at the end. Pretty great, isnā€™t it? Letā€™s enhance it. Define the curve function at the beginning of the program. This function will assist in drawing a prominent love sign for your special someone. Locate the line marked in yellow, position it at the top of the code, and insert the subsequent code there. This addition will create curves for the love sign.

t = turtle.Turtle()

def curve():
    t.pen(pencolor="white", pensize=3, speed=5)
    for i in range(200):
        t.rt(1)
        t.fd(1)

Define a Function to Draw a Big Love Symbol

Add this love_symbol function just after the previous code.

def love_sign():
    t.pen(pencolor="white",fillcolor="hot pink", pensize=3, speed=5)
    t.shape("turtle")
    t.shapesize(1,1,1)
    t.begin_fill()
    t.lt(50)
    t.fd(113)
    curve()
    t.lt(120)
    curve()
    t.fd(112)
    t.end_fill()

    t.hideturtle()

Call the `love_symbol` Function

We are at the very end of our I Love You Python Program. In the last two sections, we defined two functions to draw a prominent Love symbol adjacent to the ā€˜I Love You.ā€™ In this section, we will invoke the love_symbol function, which, in turn, will utilize the curve function to seamlessly present a substantial Love symbol.

# Calling the function for Love Sign
love_sign()

time.sleep(5)

Complete Code

Here is the complete Source Code for your convenience.

import turtle
import time
from pygame import mixer


mixer.pre_init(frequency=48000, size=-16, channels=2, buffer=512)
mixer.init()
mixer.music.load("memories.mp3")

t = turtle.Turtle()

def curve():
    t.pen(pencolor="white", pensize=3, speed=5)
    for i in range(200):
        t.rt(1)
        t.fd(1)

def love_sign():
    t.pen(pencolor="white",fillcolor="hot pink", pensize=3, speed=5)
    t.shape("turtle")
    t.shapesize(1,1,1)
    t.begin_fill()
    t.lt(50)
    t.fd(113)
    curve()
    t.lt(120)
    curve()
    t.fd(112)
    t.end_fill()

    t.hideturtle()


window = turtle.Screen()
window.bgcolor('black')
window.screensize(800, 700)
window.setup(width=1.0, height=1.0, startx=None, starty=None)

# Play Music
mixer.music.play()

t.penup()
t.goto(-80,300)
time.sleep(1)
t.pendown()
t.shapesize(1,2,1)

# 'I'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)

t.begin_fill()

t.fd(160)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(60)
t.lt(90)
# Height of 'I'
t.fd(140)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(160)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(140)
t.left(90)
t.fd(60)
t.rt(90)
t.fd(25)

t.end_fill()

# End of 'I'


t.penup()
t.goto(-550,-20)
t.pendown()


# Word: 'Love'
# 'L'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=2)
t.begin_fill()

t.rt(90)
t.fd(25)
t.rt(90)
t.fd(165)
t.lt(90)
t.fd(115)
t.rt(90)
t.fd(25)
t.rt(90)
t.fd(140)
t.rt(90)
t.fd(190)
t.rt(90)

t.end_fill()
# End of 'L'

t.penup()
t.fd(140)

# Gap between 'L' and 'O'
t.fd(70)

# 'O'
t.pen(pencolor="white",fillcolor="cyan", pensize=3, speed=8)
t.begin_fill()

t.rt(90)
t.fd(190)
t.lt(90)
t.pendown()
t.circle(60)
t.lt(90)
t.penup()
t.fd(20)
t.rt(90)
t.pendown()
t.circle(40)
t.rt(90)
t.penup()
t.fd(20)
t.lt(90)

t.end_fill()
# End of 'O'

# Gap between 'O' and 'V'
t.fd(100)
t.pendown()

# 'V'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(100)
t.fd(120)
t.rt(100)
t.fd(20)
t.rt(80)
t.fd(100)
t.lt(80)
t.fd(20)
t.lt(80)
t.fd(100)
t.rt(80)
t.fd(20)
t.rt(100)
t.fd(120)
t.rt(80)
t.fd(50)
t.lt(180)

t.end_fill()
# End of 'V'

t.penup()
# Gap between 'V' and 'E'
t.fd(100)
t.pendown()

# 'E'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(90)
t.fd(120)
t.rt(90)
t.fd(80)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(30)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(60)
t.lt(90)
t.fd(30)
t.lt(90)
t.fd(60)
t.rt(90)
t.fd(20)
t.rt(90)
t.fd(80)

t.end_fill()
# End of 'E'
# End of 'Love'

t.penup()
t.rt(180)
# Gap between 'E' and 'Y'
t.fd(200)
t.pendown()

# Start of 'You'
# 'Y'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=2)
t.begin_fill()

t.lt(90)
t.fd(50)
t.lt(30)
t.fd(80)
t.rt(120)
t.fd(20)
t.rt(60)
t.fd(60)
t.lt(180)
t.rt(60)
t.fd(60)
t.rt(60)
t.fd(20)
t.rt(120)
t.fd(80)
t.lt(30)
t.fd(50)
t.rt(90)
t.fd(20)
t.rt(180)

t.end_fill()
# End of 'Y'

t.penup()
# Gap between 'Y' and 'O'
t.fd(120)
t.pendown()

# 'O'
t.pen(pencolor="white",fillcolor="cyan", pensize=3, speed=8)
t.begin_fill()

t.circle(60)
t.lt(90)
t.penup()
t.fd(20)
t.pendown()
t.rt(90)
t.circle(40)
t.rt(90)
t.penup()
t.fd(20)
t.lt(90)

t.end_fill()
# End of 'O'

# Gap between 'O' and 'U'
t.fd(100)
t.circle(60, extent=60)
t.pendown()

# 'U'
t.pen(pencolor="white",fillcolor="dark violet", pensize=3, speed=8)
t.begin_fill()

t.lt(30)
# Height of 'U'
t.fd(85)
t.lt(90)
t.fd(20)
t.lt(90)
t.fd(70)
t.circle(-20, extent=180)
t.fd(70)
t.lt(90)
t.fd(20)
t.lt(90)
t.fd(85)
t.circle(40, extent=180)

t.end_fill()
# End of 'U'
# End of 'You'

t.penup()
# t.goto(300,130)
t.rt(180)
t.fd(35)
t.lt(90)
t.fd(140)
t.lt(90)
t.pendown()

# Calling the function for Love Sign
love_sign()

time.sleep(5)

Output

The above program outputs the following:

Output

Summary

Expressing love goes beyond usual methods and involves a unique type of coding. In this tutorial, we embark on a journey where lines of Python code weave a love story. Using the Turtle module, we craft a Program to say I Love You in Python in a visual way with letters and symbols for your special someone.

As the Python script runs, each line drawn on the screen tells a love story. Starting with ā€˜I,ā€™ moving through ā€˜Love,ā€™ and ending with ā€˜You,ā€™ the code becomes a canvas expressing feelings.

So, express your feelings in Python, where each line of code tells a story, and love is shown not just in words but in the beauty of programming. Run the code, play the music, and see your emotions on the screenā€”a tribute to the endless creativity that love sparks.

Craving coding adventures? Dive into the secret stash of Cool Python Programs hidden behind this portalšŸŖ„. Below are a few instances to spark your interest.āœØ

Do you have any burning questions about the topic? Donā€™t be shyā€”drop them in the comments below! Iā€™m here and ready to help you out.

Happy Coding!

Share your love
Subhankar Rakshit
Subhankar Rakshit

Hey there! Iā€™m Subhankar Rakshit, the brains behind PySeek. Iā€™m a Post Graduate in Computer Science. PySeek is where I channel my love for Python programming and share it with the world through engaging and informative blogs.

Articles:Ā 194