Say I Love You using Python Code

a boy and a girl are sitting on a bench in a park

Introduction

Are you in love with someone? If your answer is yes and you're a programmer then this article will help you a lot.

Every lover tries to show his/her love to his/her beloved person in a different way. Their are so many ways to surprise him/her. For example, writing a poem, dedicating a special song, cute notes, eye-catching gifts, letters, and much more.

These are popular ways majority of people follow. But as a python programmer the idea came to my mind, if a program could be created to say I Love You then it would be a great and unpredictable method.

In this tutorial, I will show you How You can say I Love You to your beloved person using a Python Code.

Requirements

You need to install these python libraries before writing the code for your beloved person. 

Turtle: pip install PythonTurtle

pygame(Optional): pip install pygame

output of I love you python program
Output of the Program

Import the Modules

Let's create a python file with the name 'ILoveYou.py' and start writing your code by importing these modules. Next, create an instance of the Turtle class.


import turtle
import time
from pygame import mixer

# Intialize Turtle module
t = turtle.Turtle()

Initialize the PyGame mixer (Optional)

Initialize the PyGame mixer to play an music in the background. The reason I said it optional because, you can avoid adding the music part. But a music can represent output of the program more better.

See, the yellow line. You just need to mention the path of the music file here. If you download the entire file from my GitHub page(through the Download button given below), you'll find a music file I already added there.


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

Set the Background Window

Set the background color of the Turtle window, size, etc. I used black color for the background. You can choose another one.

The window size I selected here is 800x700. You can choose a different size as per your screen size.


# Window decorations
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 (Optional)

Play the music you have added just one step before. Comment this line if you don't want to play the music in the background.


# Play Music
mixer.music.play()

Draw 'I' letter

Now start drawing with the 'I' letter. It's so simple. Here, I just command the Turtle with different numbers for moving forward, backward, left, right, and turn around an angle.


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

# Letter: '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 the '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 'Love' word

I hope, your code is drawing the 'I' letter successfully. Now we need write the 'Love' word to express your thoughts about him/her. 

The logic is same as the previous. This time I just compacted the code into one to draw the entire word instead of drawing a single letter.


# End of 'I'


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


# Draw 'Love'
# Letter: '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)

# Letter: '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()

# Letter: '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()

# Letter: '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'

Draw 'You' word

We are almost at end of our program. Now draw the 'You' word as the same way like before. Use this code to do it.

 
# End of 'E'

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

# Letter: '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()
t.fd(120)
t.pendown()

# Letter: '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()

# Letter: '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'

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

Define 'curve()' function

Our program is drawing 'I Love You' perfectly. Everything is perfect but if a love sign could be added at the end, how it would look? Great! right? Let's do it.

Define a 'curve()' function at the top of the program which will draw the big love sign for your loved person. See the yellow marked line, find this line at the top of the code and paste the next code there. It will draw 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 sign

Add this function just after the previous code.


# Function to draw the love sign
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 decorations

Call the love_sign() function

Add these two lines at the very end of your main python program.


# Calling the function love_sign
love_sign()

time.sleep(5)

Now the code is ready to run.

Full Code

Here is the full code for your convenience.


"""I Love You in Python"""
import turtle
import time
from pygame import mixer

# Intialize Turtle module
t = turtle.Turtle()

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

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

# Function to draw the love sign
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 decorations
window = turtle.Screen()
window.bgcolor('black')
window.screensize(800, 700)
window.setup(width=1.0, height=1.0, startx=None, starty=None)

# Play Music(Optional)
mixer.music.play()

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

# Letter: '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 the '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()


# Draw 'Love'
# Letter: '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)

# Letter: '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()

# Letter: '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()

# Letter: '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'

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

# Letter: '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()
t.fd(120)
t.pendown()

# Letter: '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()

# Letter: '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'

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 love_sign
love_sign()

time.sleep(5)

Download the code

Summary

In this tutorial, we build a python program for our beloved person. It will help to express your love as a programmer. The program draws 'I Love You💕' on the black screen and plays a beautiful music in the background as well as.

Do use this code in the real-life too. You can modify this code by changing the color, word size, turtle speed, music selection, etc. It's completely your choice. I hope he/she will love your work. 

There is another way to say I Love You through python programming. I have made a separate article on this topic in detail. Here, the program prints "I Love You" message with the person's name in the form of ASCII text art. Check this out also: Wish Your Friends with Stylish Text in Python.

To get more lovely python topics, visit the separate page created only for Unique Examples. Some examples are given below.

👉Extract Text from an Image using a Python Program 

👉Draw the Sketch of Lionel Messi using a Python Program 

👉Extract Metadata from an Image using Python 

👉Check the strength of your password using python 

Thanks for reading!💙

PySeek

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

4 Comments

  1. I will use it upcoming valentine's day.

    ReplyDelete
  2. Great job my dear friend. But I'm sad to see someone had copied your code line by line and is using it on his/her website.

    ReplyDelete
  3. Replies
    1. If you download the code from my GitHub page, you will see, I used a piece of music for playing in the background while running the code. But many people got a problem with that. That's why I removed the music from the main code here. Now it has become very easy to run by everyone.

      Delete
Post a Comment
Previous Post Next Post