Birthday Wish Using Python Code

Happy Birthday Wish Using Python Code

Happy Birthday Wishes

Today we will wish happy birthday to our friend and that too in a new way using Python, so let’s start making this program step by step. Everyone wishes normally so that we can do something interesting for our loved ones, in the style of a coder. and this is a new and fun way to wish someone a birthday, the birthday boy or girl will be very happy by watching the program and if you want to add something to it then you can do that too, so we made for you.

Happy Birthday Wishes

Now start the code:-

1. import module:-

First of all we will import some modules which will help in drawing cake and playing music.

import turtle
import random
import time
from pygame import mixer

2. Initializing Music:-

pygame module is used to mix the music and you set the music path according to your file path.

mixer.init()
mixer.music.load("happy-birthday-song.mp3")
mixer.music.play()

Birthday Wish Using Python

3. Creating Colorful Background:-

In this code we reparing the turtle screen with a background, Next we can draw three lines to create the foundation of the birthday card.

bg = turtle.Screen()
bg.bgcolor("black")

# Bottom Line 1
# Mid Line 2
# First Line 3
# Gradual background color changes

OutPut Preview:-

Birthday Wish Using Python

4. Drawing the Cake:-

You can create a birthday cake using turtle graphics in this program.

# Cake
# Candles
# Decoration

OutPut Preview:-

Happy Birthday Wish Using Python Code

5. Adding a Colorful Circles:-

The circles will change colors and form a pattern.

# Decoration
colors = ["red", "orange", "yellow", "green", "blue", "purple", "black"]
# Loop to draw circles with changing colors

OutPut Preview:-

Birthday Wish Using Python

6. Now Displaying the Birthday Message:-

In this code we program the turtle in a position to write a birthday message and add an interesting animation

# Happy Birthday message with bouncing animation
# ENTER YOUR NAME IN THE NAME PLACE
# Bouncing Animation

Output Preview:-

Happy Birthday Wish Using Python Code

This is a new and fun way to wish someone a birthday, the birthday boy or girl will be very happy by watching the program and if you want to add something to it then you can do that too, so we have made step by step program for you.

Here is the full code :-

import turtle
import random
import time
from pygame import mixer

# Adding music is optional as per your choice.
mixer.init()
mixer.music.load("happy-birthday-song.mp3")  # add your music file name or path

# sets background
bg = turtle.Screen()
bg.bgcolor("black")
mixer.music.play()

# Bottom Line 1
turtle.penup()
turtle.goto(-170, -180)
turtle.color("white")
turtle.pendown()
turtle.forward(350)

# Mid Line 2
turtle.penup()
turtle.goto(-160, -150)
turtle.color("white")
turtle.pendown()
turtle.forward(300)

# First Line 3
turtle.penup()
turtle.goto(-150, -120)
turtle.color("white")
turtle.pendown()
turtle.forward(250)
bg.bgcolor("lightgreen")

# Cake
turtle.penup()
turtle.goto(-100, -100)
turtle.color("white")
turtle.begin_fill()
turtle.pendown()
turtle.forward(140)
turtle.left(90)
turtle.forward(95)
turtle.left(90)
turtle.forward(140)
turtle.left(90)
turtle.forward(95)
turtle.end_fill()
bg.bgcolor("lightblue")

# Candles
turtle.penup()
turtle.goto(-90, 0)
turtle.color("red")
turtle.left(180)
turtle.pendown()
turtle.forward(20)
turtle.penup()
turtle.goto(-60, 0)
turtle.color("blue")
turtle.pendown()
turtle.forward(20)
turtle.penup()
turtle.goto(-30, 0)
turtle.color("yellow")
turtle.pendown()
turtle.forward(20)
turtle.penup()
turtle.goto(0, 0)
turtle.color("green")
turtle.pendown()
turtle.forward(20)
turtle.penup()
turtle.goto(30, 0)
turtle.color("purple")
turtle.pendown()
turtle.forward(20)
bg.bgcolor("orange")

# Decoration
colors = ["red", "orange", "yellow", "green", "blue", "purple", "black"]
turtle.penup()
turtle.goto(-40, -50)
turtle.pendown()

for each_color in colors:
    angle = 360 / len(colors)
    turtle.color(each_color)
    turtle.circle(10)
    turtle.right(angle)
    turtle.forward(10)

bg.bgcolor("red")

# Happy Birthday message with bouncing animation
turtle.penup()
turtle.goto(-150, 50)
turtle.color("yellow")
turtle.pendown()

# ENTER YOUR NAME IN THE NAME PLACE
turtle.write(arg=f"Happy Birthday CodeWithRandom!", align="center", font=("jokerman", 20, "normal"))
time.sleep(1.5)
# Bouncing Animation
for _ in range(7):
    turtle.penup()
    turtle.goto(-150, 50)
    turtle.pendown()
    turtle.clear()
    turtle.penup()
    turtle.goto(-150, 50 - _ * 10)
    turtle.pendown()
    turtle.write(arg=f"Happy  Birthday  CodeWithRandom!", align="left", font=("jokerman", 20, "normal"))
    time.sleep(0.5)

turtle.done()

Final Output Preview :-

Thanks for reading this article, stay with us for such interesting programs like Birthday Wishing, we have explained to you step by step easy to learn this project 

Author :-  Ashutosh Mishra

ADVERTISEMENT

Visit my more article:- codewithrandom

ADVERTISEMENT

FAQs:-

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Which modules need to be imported to create this program?

These are some modules from which we created the birthday wishing program. ( mixer pygame time random )

How to add music in is birthday wishing program

To add music to this program we used this code:-
mixer.init()
mixer.music.load("happy-birthday-song.mp3") # add your music file name or path



This Post Has 2 Comments

  1. Bhanu Pratap Singh

    Big fan Ashutosh Bhaiya. Aap k coding se bhut help ho jata h. Isi tarah hmlog k madad krte rahiye.

    1. Ashutosh Mishra

      thanks dear

Leave a Reply