Created
September 18, 2020 04:29
-
-
Save ibelgin/a9ff88bfd4dfb2e4c7677eac45ff0bc2 to your computer and use it in GitHub Desktop.
Python Music Player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
from tkinter.filedialog import askopenfile | |
from pygame import mixer | |
file_name = "" | |
window=Tk() | |
window.title("Music Player") | |
window.geometry("650x400") | |
def open_file(): | |
file = askopenfile(mode ='r', filetypes =[('Music Files', '*.mp3')]) | |
global file_name | |
file_name = file.name | |
def play(): | |
try: | |
mixer.init() | |
mixer.music.load(file_name) | |
mixer.music.set_volume(0.5) #For Playing The Audio | |
mixer.music.play() | |
except: | |
root_window = Tk() | |
root_window.title("Error") | |
root_window.geometry("40x100") | |
w = Label(root_window, text=" Error !! Choose a Song") | |
w.grid(column=1,row=1) | |
w.pack() | |
root_window.mainloop() | |
def Pause(): #For Pausing The Audio | |
mixer.music.pause() | |
def UnPause(): #For Unpausing The Audio | |
mixer.music.unpause() | |
def stop(): #To Stop The Song | |
mixer.music.stop() | |
btn=Button(window,text=" Stop The Song ",command=stop) | |
btn.grid(column=0,row=2) | |
btn=Button(window,text=" Start To Play ",command=play) | |
btn.grid(column=1,row=2) | |
btn=Button(window,text=" Pause The Song ",command=Pause) | |
btn.grid(column=2,row=2) | |
btn=Button(window,text=" UnPause The Song ",command=UnPause) | |
btn.grid(column=3,row=2) | |
btn=Button(window,text=" Choose File ",command=open_file) | |
btn.grid(column=2,row=0) | |
window.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment