Hello friends, do you know that there are many ways to make music players from simple to advanced levels?
Here, we are presenting you with two very very basic music player in python.
One of them is a simple program and the other one is a GUI program.
For the simple program, we have used pygame which is a famous gaming module in python and its use is very simple.
So, you need to install pygame inside your system if you don’t have it.
To install pygame type "pip install pygame"
inside cmd.
For the GUI one, you should have tkinter and pygame both.
There are so many small tkinter projects which you can see if you have any problem with tkinter.
So, now let’s see the codes for both programs.
Code for the GUI program
from pygame import mixer from tkinter import * root = Tk() root.geometry("600x300") mixer.init() mixer.music.load("filename.mp3") def pause(): mixer.music.pause() def play(): mixer.music.play() def resume(): mixer.music.unpause() Label(root, text="Welcome to music player", font="lucidia 30 bold").pack() 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) root.mainloop()
Output:
Code for simple program
import pygame from pygame import mixer pygame.init() mixer.init() screen = pygame.display.set_mode((600, 400)) mixer.music.load("filename.mp3") mixer.music.play() print("Press 'p' to pause 'r' to resume") print("Press 'q' to quit") running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_p: mixer.music.pause() if event.key == pygame.K_r: mixer.music.unpause() if event.key == pygame.K_q: running = False quit()
You just need to copy and paste it into your IDE and just run it. And also don’t forget that your music file with the name ‘filename’ should be at the same place where your program exists i.e. they both should be inside the same directory
Thanks for reading
If you have any queries then feel free to comment
Keep with us as we post much content like this
Also read:
- Create your own ChatGPT with Python
- SQLite | CRUD Operations in Python
- Event Management System Project in Python
- Ticket Booking and Management in Python
- Hostel Management System Project in Python
- Sales Management System Project in Python
- Bank Management System Project in C++
- Python Download File from URL | 4 Methods
- Python Programming Examples | Fundamental Programs in Python
- Spell Checker in Python
- Portfolio Management System in Python
- Stickman Game in Python
- Contact Book project in Python
- Loan Management System Project in Python
- Cab Booking System in Python
- Brick Breaker Game in Python
- Tank game in Python
- GUI Piano in Python
- Ludo Game in Python
- Rock Paper Scissors Game in Python
- Snake and Ladder Game in Python
- Puzzle Game in Python
- Medical Store Management System Project in Python
- Creating Dino Game in Python
- Tic Tac Toe Game in Python
- Test Typing Speed using Python App
- Scientific Calculator in Python
- GUI To-Do List App in Python Tkinter
- Scientific Calculator in Python using Tkinter
- GUI Chat Application in Python Tkinter