Python Tkinter Script to Play Sound Using Pygame Library in Application Full Project For Beginners

Python Tkinter Script to Play Sound Using Pygame Library in Application Full Project For Beginners

 

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

 

 

 

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

 

See also  Python Tkinter Listbox Widget to Display or Insert List of Data in GUI Desktop App Full Project For Beginners

 

 

Now if you execute this python file app.py by executing the following command

 

python app.py

 

You will see the following screenshot

 

 

 

Leave a Reply