#Building a music player import os from tkinter.filedialog import askdirectory import pygame from tkinter import* root = Tk() root.minsize(450,500) listofsongs = [] v = StringVar() songlabel = Label(root,textvariable = v,width = 25) index = 0 def nextsong(event): global index index += 1 pygame.mixer.music.load(listofsongs[index]) pygame.mixer.music.play() updatelabel() def prevsong(event): global index index -= 1 pygame.mixer.music.load(listofsongs[index]) pygame.mixer.music.play() updatelabel() def stopsong(event): pygame.mixer.music.stop() v.set(" ") #return songname def updatelabel(): global index global songname v.set(listofsongs[index]) return songname def directory_chooser(): directory = askdirectory() os.chdir(directory) for files in os.listdir(): if files.endswith(".mp3"): listofsongs.append(files) pygame.mixer.init() pygame.mixer.music.load(listofsongs[0]) pygame.mixer.music.play() directory_chooser() label = Label(root,text="Audio Music Player") label.pack listbox = Listbox(root) listbox.pack() listofsongs.reverse() for items in listofsongs: listbox.insert(0,items) listofsongs.reverse() nextbutton = Button(root,text = "Next Song") nextbutton.pack() previousbutton = Button(root,text = "Previos Song") previousbutton.pack() stopbutton = Button(root,text = "Stop Song") stopbutton.pack() nextbutton.bind("",nextsong) previousbutton.bind("",prevsong) stopbutton.bind("",stopsong) songlabel.pack() root.mainloop()