Pythondex
Turtle Python Programs

Python Program To Wish Happy New Year

Last updated June 8, 2023 by Jarvis Silva

In this tutorial we will create a Python Program To Wish Happy New Year, you can use this program to wish new year to your friends and relatives, they will surely find it amazing and interesting if they are programmers.

Inorder to create this program we will have to use the turtle library, which is a gui library and also pygame library it will allow us to add music to the program.

Python Code To Wish Happy New Year


import turtle
from pygame import mixer

# Adding music is optional as per your choice.
# Initialize pygame mixer
mixer.pre_init(frequency=48000, size=-16, channels=2, buffer=512)
mixer.init()
mixer.music.load("sound.mp3") #add your music file name or path


screen = turtle.Screen()

screen.bgcolor('#000')
screen.title("Happy new year 2022")
screen.screensize(800,800)

mixer.music.play()


firework = turtle.Turtle()
firework.pensize(3)
firework.shape('turtle')
size = 20
firework.stamp
firework.speed(11)
firework.left(90)

firework.color("#EA2027")
for step in range(40):
    firework.forward(100)
    firework.left(180)
    firework.forward(100)
    firework.left(9)

firework.color('#EE5A2A')
for step in range(36):
    firework.forward(130)
    firework.left(180)
    firework.forward(130)
    firework.left(10)

firework.color('#F79F1F')
for step in range(20):
    firework.forward(150)
    firework.left(180)
    firework.forward(150)
    firework.left(18)

firework.color('#3ae374')
for stamps in range(12):
    firework.penup()
    firework.forward(170)
    firework.pendown()
    firework.forward(10)
    firework.penup()
    firework.forward(10)
    firework.stamp()
    firework.right(30)
    firework.penup()
    firework.setpos(0,0)


text = turtle.Turtle()
text.color("#fff")
text.penup()
text.setpos(0,-240)
text.write("Happy New Year 2023", True, align="center", font=("Monsterrat", 20, "normal"))
text.setpos(0,-260)

screen.mainloop()

Above is the code for wishing happy new year, if you take a look at the code it is all made using turtle functions so let’s see how the code works:

  • The code imports the required libraries: turtle and mixer from Pygame.
  • Pygame mixer is initialized with specific settings for sound playback.
  • The code loads a music file (“sound.mp3”) to be played during the animation.
  • The turtle screen is created with a black background and a title.
  • The music is played using the mixer.
  • A turtle named “firework” is created with specific attributes (size, shape, color, speed).
  • The firework turtle draws a firework shape using a series of forward and left turns.
  • The process is repeated for different colors to create different layers of the firework.
  • Another turtle named “text” is created to display the text “Happy New Year 2023” at the bottom of the screen.
  • The turtle screen enters the main event loop, allowing the animation to be displayed until the user closes the window.

There is a music in this program which will play so before you run the program you have to have the music file so download the music file from below it also contains the code.

We have used the turtle and pygame module to do this program which comes installed with python setup so you don’t have to manually install it but still if you get any errors like turtle or pygame module is not found then you can install both libraries by using the below commands.


# To install turtle
pip install turtle
# To install pygame
pip install pygame

You can use an online python compiler to run this program or you can run it on your computer, when you run the program it will start a new window and wish you happy new year by drawing it will also play the music below is the output of this program.

Happy new year program output python

As you can see we have successfully wished happy new year using python, I hope you ran this program successfully and found it helpful.

Want a python program for wishing your friends birthday then refer to this guide: Python Program To Wish Happy Birthday With Code.

I hope you found what you were looking for from this python tutorial and if you want more tutorials like this in the future then do join our Telegram channel.

Thanks for reading, Happy new year 🙂