In this blog, I’ll Walk you through building a best music player in Python using Tkinter and Pygame for GUI and handling audio playback, respectively.
It’s simple, beginner-friendly, and doesn’t require deep knowledge of Python. It is considered as one of the most preferable project for resume as well.

Only 2 libraries we need for this project:
To build this project, we’ll use two main Python libraries:
- Tkinter – This is Python’s standard GUI library. It helps us build the visual part of our app like buttons, windows, and labels.
- pygame.mixer – This comes from the Pygame library. It’s used to load and control audio playback like playing, pausing, and resuming music.
Before starting, make sure you have pygame installed. If not, open your terminal and type:
pip install pygame
Tkinter comes pre-installed with Python, so no need to install it separately.
What We’ll Create
We’re going to make a simple windowed application that allows you to:
- Play a music file
- Pause it
- Resume the paused music
- Quit the app when you’re done
The design will be basic but functional. You’ll see a heading and four buttons for controlling the music. Perfect for beginners and anyone curious about audio apps in Python.
Complete Code for Music Player in Python Using Tkinter and Pygame
from pygame import mixer from tkinter import * # Create the main application window root = Tk() root.geometry("600x300") # Set the window size # Initialize the mixer module mixer.init() # Load your MP3 file (make sure the file is in the same directory) mixer.music.load("filename.mp3") # Change filename.mp3 to your actual file # Function to pause the music def pause(): mixer.music.pause() # Function to play the music def play(): mixer.music.play() # Function to resume music after it is paused def resume(): mixer.music.unpause() # Add a heading label to the window Label(root, text="Welcome to music player", font="lucida 30 bold").pack() # Add control buttons Button(text="Play", command=play).place(x=200, y=100) Button(text="Pause", command=pause).place(x=250, y=100) Button(text="Resume", command=resume).place(x=310, y=100) Button(text="Quit", command=quit).place(x=380, y=100) # Keep the window running root.mainloop()
Let’s Understand This Code Logic:
a) Setting Up the Window
<strong>root = Tk()<br>root.geometry("600x300")</strong>
This creates the main application window using Tkinter. We also set a fixed window size of 600 pixels wide and 300 pixels tall.
b) Initializing the Mixer
<strong>mixer.init()</strong>
The mixer
module from pygame
needs to be initialized before you can play any audio. This sets up the audio system.
C) Loading the Music File
<strong>mixer.music.load("filename.mp3")</strong>
Replace "filename.mp3"
with the name of your audio file. Make sure your file is in the same folder as your Python script, or you’ll get an error.
d) Music Play Button Function
<strong>def play():<br> mixer.music.play()</strong>
If you want to temporarily stop the music without closing the player, you can use this function. The song will pause wherever it was.
e) Pause Music Button Function
def pause():<br> mixer.music.pause()
If you want to temporarily stop the music without closing the player, you can use this function.
f) Resume Music Button Function
<strong>def resume():<br> mixer.music.unpause()</strong>
This function continues the music from where it was paused.
How to Run the App
- Save the script in a Python file (e.g.,
music_player.py
). - Put your MP3 file in the same folder as your script.
- Run the script using:
python music_player.py
Once the window appears, click the buttons to test the functionality.
Conclusion
Creating a basic music player using Python may sound difficult, but with the help of Tkinter and Pygame, it becomes a very doable project, even for someone in their first year of learning Python.
You’ve built a real, working app that lets you play music from your computer. You’ve also learned how to set up a GUI, handle user input with buttons, and control media playback.
For more such amazing python projects visit here