Welcome folks today in this blog post we will be playing sound inside application
in python using pygame
library. All the source code of the application is shown below.
Get Started
In order to get started you need to install python
inside our system. After installing it we need to install python game
library called pygame
using pip
command
pip install pygame
After installing this library you can create an app.py
file inside our root directory like this and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# importing required libaraies from tkinter import * import pygame root = Tk() root.title('GeeksforGeeks sound player') root.geometry("500x400") pygame.mixer.init()# initialise the pygame def play(): pygame.mixer.music.load("1.mp3") pygame.mixer.music.play(loops=0) title=Label(root,text="GeeksforGeeks",bd=9,relief=GROOVE, font=("times new roman",50,"bold"),bg="white",fg="green") title.pack(side=TOP,fill=X) play_button = Button(root, text="Play Song", font=("Helvetica", 32), command=play) play_button.pack(pady=20) root.mainloop() |
Now if you execute this python file
app.py by executing the following command
python app.py
You will see the following screenshot