How to Make a Music Player Using Python

How to Make a Music Player Using Python

Published at - Nov 02, 2021

Hello there!

Today we’ll use Python to create a GUI for our music player. There will be no more conversations; prepare with your interpreter!

Why do I want it? To learn and boost my Python skills.


  1. Python Fundamentals knowledge

  2. Tkinter and PyGame should be installed. After that, we must import modules.


pip install pygame

Start Coding

Code with explanation:

<iframe src="" frameborder=0></iframe>

  • Import required packages at the top of that Python file.

<iframe src="" frameborder=0></iframe>

  • The music is played using the playsong() method. It plays the needed music after loading the active song from the list. When the user presses the “play” button, it is activated.

  • The currentsong() function prints the currently playing song/music in the PlayList. It sets ‘Playing’ as the song state.

<iframe src="" frameborder=0></iframe>

  • These three functions are all interconnected. The pausesong() method stops the music and changes the status to “Paused.” The stopsong() method and resumesong() method perform the same functions as their names suggest.

<iframe src="" frameborder=0></iframe>

  • The primary GUI window is called root in this case. The window’s title is set by root.title. (Change it as you want)

<iframe src="" frameborder=0></iframe>

  • These are also GUI-related. The letters ‘fg’ and ‘bg’ stand for foreground and backdrop, respectively.

  • playlist.grid() uses absolute row and column coordinates to place widgets in a two-dimensional grid.

<iframe src="" frameborder=0></iframe>

  • In Python, the chdir() method is used to change the current working directory to a given path. As for the new directory path, it only accepts one option.

  • The Python listdr() function is used to acquire a list of all files and folders in a given directory. If we don’t provide a directory, the current working directory’s list of files and directories will be returned.

  • It adds all of the files in our file directory into the playlist in the ‘for’ loop.

<iframe src="" frameborder=0></iframe>

This is the final section. These are all lines for GUI Buttons.

  • command is a verb that means “to command.” The common name is the name of the function that we created originally. For example, resumesong and playsong. All other GUI variables were discussed previously.

Full Code

<iframe src="" frameborder=0></iframe>

Finally, you’ve created your Python music player! Congratulations, friend!

Since we want only the music player, don’t care much about GUI.😉

I hope you enjoy this modest music player with few options. Don’t forget to applaud for this article and follow me.

Thank you for reading!

More content at

Related Posts -

10 Python Tips and Tricks that You Do Not Know
10 Python Tips and Tricks t ...

Today, I am going to share 10 clever Python tips and tricks that you can us...

5 Most Useful Scripts in Python
5 Most Useful Scripts in Py ...

Hello everyone, This is my first post on a useful Python script. I will pub...

Face recognition under 25 lines of code with Python
Face recognition under 25 l ...

In this article, we will look at an amazingly simple way to get started wit...

Python tutorial - What is programming?
Python tutorial - What is p ...

What is programming? As a computer user, you know that computers have no f...

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile