A lightweight desktop music player application built with Python, featuring a graphical user interface created with Tkinter and audio playback powered by Pygame Mixer.
The application scans a specified local directory for .mp3 files and displays them in a playlist, allowing users to select and control their music directly from the GUI.
- ๐ต Load local
.mp3audio files. - ๐ Automatically scan a configured music directory.
- ๐ Display available songs in a playlist.
โถ๏ธ Play selected songs.- โธ๏ธ Pause and resume playback.
- โน๏ธ Stop the current song.
- โฎ๏ธ Navigate to the previous song.
- โญ๏ธ Navigate to the next song.
- ๐จ Dark-themed desktop interface.
- ๐ผ๏ธ Custom button icons.
- ๐ Audio playback using Pygame Mixer.
The application provides a simple desktop music-player interface consisting of:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Music Player โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ song_01.mp3 โ โ
โ โ song_02.mp3 โ โ
โ โ song_03.mp3 โ โ
โ โ song_04.mp3 โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Currently Playing โ
โ โ
โ โฎ โน โถ โธ โญ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Button | Function |
|---|---|
| โฎ๏ธ Previous | Plays the previous song in the playlist |
| โน๏ธ Stop | Stops playback and clears the selection |
| Plays the selected song | |
| โธ๏ธ Pause | Pauses or resumes the current song |
| โญ๏ธ Next | Plays the next song in the playlist |
The application uses several Python modules to handle the GUI, filesystem operations, file filtering, and audio playback.
Tkinter creates the main application window:
canvas = tk.Tk()
canvas.title("Music player")
canvas.geometry("600x800")
canvas.config(bg="black")Pygame Mixer handles audio playback:
from pygame import mixer
mixer.init()The application searches the configured directory for .mp3 files:
pattern = "*.mp3"
for root, dirs, files in os.walk(rootpath):
for filename in fnmatch.filter(files, pattern):
listBox.insert("end", filename)When a song is selected, its filename is retrieved from the playlist and loaded into the mixer:
mixer.music.load(rootpath + "\\" + listBox.get("anchor"))
mixer.music.play()The application allows navigation through the songs using the selected playlist index.
Current Song
โ
โโโ Previous โ Song - 1
โ
โโโ Next โ Song + 1
The application uses Pygame Mixer to pause and resume the current track:
mixer.music.pause()
mixer.music.unpause()The main programming language used to develop the application.
Used to create the graphical user interface, including:
- Main window
- Playlist
- Buttons
- Labels
- Frames
Used for:
- Loading audio files
- Playing music
- Pausing playback
- Resuming playback
- Stopping playback
Used to navigate through the music directory and discover audio files.
Used to filter files based on the .mp3 pattern.
Music-Player/
โ
โโโ MusicPlayer.py
โโโ prev_img.png
โโโ stop_img.png
โโโ play_img.png
โโโ pause_img.png
โโโ next_img.png
โโโ README.md
The button image files are required by the application because they are loaded directly using
tk.PhotoImage.
git clone https://github.com/MostafaNabil21/MusicPlayer.git
cd MusicPlayerTkinter is included with most standard Python installations. Install Pygame with:
pip install pygameSet the rootpath variable in the Python file to the directory containing your MP3 files:
rootpath = "C:\\Users\\YourName\\Music"For example:
rootpath = "D:\\Music"The application searches this directory and adds matching .mp3 files to the playlist.
Run the Python file:
python MusicPlayer.pyThe Music Player window will open and display the available MP3 files.
Select a song from the playlist and use the playback controls to control the music.
| Function | Purpose |
|---|---|
select() |
Loads and plays the selected song |
stop() |
Stops the current song |
play_next() |
Plays the next song |
play_prev() |
Plays the previous song |
pause_song() |
Pauses or resumes playback |
This project demonstrates practical Python programming concepts including:
- Object-oriented GUI framework usage
- Event-driven programming
- Function-based application design
- File-system traversal
- File pattern matching
- GUI widgets
- Button callbacks
- Playlist management
- Audio playback
- External Python libraries
- Local file handling
Possible improvements for future versions include:
- ๐ Shuffle mode
- ๐ Repeat mode
- ๐ Volume control
- โฑ๏ธ Song progress bar
- โญ๏ธ Automatic next-song playback
- ๐ Browse/select music folder from the GUI
- ๐ผ Support for additional audio formats
- ๐ผ๏ธ Album artwork
- ๐๏ธ Audio volume slider
- ๐ Editable playlists
- ๐ Song search
- ๐พ Save playlists between sessions
Through this project, I practiced building a complete desktop application with Python by combining:
Python
โ
Tkinter GUI
โ
File System Handling
โ
Playlist Management
โ
Pygame Audio Engine
โ
Interactive Music Player
The project demonstrates how Python can be used to build interactive desktop applications that combine graphical interfaces with real-time audio functionality.