This creates a simple GUI, and buttons to open a file, play, pause, and stop the music. When you click the "Open" button, a file dialog will appear and you can select an MP3 file to add to the playlist. When you click the "Play" button, the first song in the playlist will start playing. If you click the "Pause" button, the music will pause, and if you click it again, it will resume playing. Clicking the "Stop" button will stop the music and reset the player.
from tkinter import *
from pygame import mixer
import tkinter.messagebox
from tkinter import filedialog
mixer.init()
class Musicplayer:
def __init__(self,Tk):
self.root=Tk
self.root.title("EBS MUSIC PLAYER")
self.root.geometry("600x450")
self.root.configure(background="white")
#menubar
self.menubar=Menu(self.root)
#Now Attach With Windwo
self.root.configure(menu=self.menubar)
def myselfinfo():
tkinter.messagebox.showinfo("About Us","Music Player Created by EBS Contact : 7551865174")
def openfile():
global filename
filename=filedialog.askopenfilename()
#Create Submenu
self.submenu=Menu(self.menubar,tearoff=0)
self.menubar.add_cascade(label="File",menu=self.submenu)
self.submenu.add_command(label="Open",command=openfile)
self.submenu.add_command(label="Exit",command=self.root.destroy)
self.submenu2 = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="About", menu=self.submenu2)
self.submenu2.add_command(label="Help",command=myselfinfo)
# Ekahne Background image ekta variable er moddye rakhbo
self.mainbackground = PhotoImage(file="backgroundblackmusic.png")
canvas = Canvas(self.root, width=600, height=450)
canvas.pack(fill=BOTH, expand=True)
canvas.create_image(0, 0, image=self.mainbackground, anchor='nw')
# PlayMusic Function
def play_music():
# For Pause play music after pause
try:
paused
except NameError:
try:
mixer.music.load(filename)
mixer.music.play()
except:
tkinter.messagebox.showerror('Error',"File Could Not Found")
else:
mixer.music.unpause()
# PauseMusic Function
def pause_music():
global paused
paused=TRUE
mixer.music.pause()
# StopMusic Function
def stop_music():
mixer.music.load(filename)
mixer.music.stop()
self.playbutton_phpto=PhotoImage(file="bt2.png")
playbutton=Button(self.root,image=self.playbutton_phpto,bd=0,highlightthickness=0,bg="white",command=play_music).place(x=90,y=390)
self.posbutton_phpto = PhotoImage(file="bt3.png")
posbutton = Button(self.root, image=self.posbutton_phpto, bd=0, highlightthickness=0,bg="white",command=pause_music).place(x=142, y=390)
self.stopbutton_phpto = PhotoImage(file="bt7.png")
stopbutton = Button(self.root, image=self.stopbutton_phpto, bd=0, highlightthickness=0,bg="white",command=stop_music).place(x=195, y=390)
# For Sound + -
# Creat a Scale
# mute
def mute():
self.soundpm.set(0)
self.mute = PhotoImage(file="bt8.png")
mute = Button(self.root, image=self.mute,bd=0, command=unmute,bg="white").place(x=248, y=390)
def unmute():
self.soundpm.set(25)
self.unmute = PhotoImage(file="bt6.png")
unmute = Button(self.root, image=self.unmute,bd=0, command=mute,bg="white").place(x=248, y=390)
def volume(vol):
# Ja value pacchi seta k 100 diea /
volm=int(vol)/100
mixer.music.set_volume(volm)
self.volimg=PhotoImage(file="bt6.png")
volimg=Button(self.root,image=self.volimg,bd=0,bg="white",command=mute).place(x=248,y=390)
self.soundpm=Scale(self.root,from_=0,to=100,orient=HORIZONTAL,bd=0,bg='orange',command=volume)
# Set Default value 25
self.soundpm.set(25)
self.soundpm.place(x=305,y=390,height=52)
root=Tk()
obj=Musicplayer(root)
root.mainloop()
Download Full Project: music.zip
No module named PIL Install PIL module: If you haven't installed PIL yet, install it using pip, the..
Lambda is a small and anonymous function in Python, where you can use many arguments but only ..
Connect with mysql database using python Install the mysql-connector-python-rf - $..
Insert data into MySQL table using Python. Install mysqlclient Open Terminal..
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !