Guest User

Untitled

a guest
Jan 29th, 2017
8,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. import os
  2. from tkinter.filedialog import askdirectory
  3.  
  4. import pygame
  5. from mutagen.id3 import ID3
  6. from tkinter import *
  7.  
  8. root = Tk()
  9. root.minsize(300,300)
  10.  
  11.  
  12. listofsongs = []
  13. realnames = []
  14.  
  15. v = StringVar()
  16. songlabel = Label(root,textvariable=v,width=35)
  17.  
  18. index = 0
  19.  
  20. def directorychooser():
  21.  
  22.     directory = askdirectory()
  23.     os.chdir(directory)
  24.  
  25.     for files in os.listdir(directory):
  26.         if files.endswith(".mp3"):
  27.  
  28.             realdir = os.path.realpath(files)
  29.             audio = ID3(realdir)
  30.             realnames.append(audio['TIT2'].text[0])
  31.  
  32.  
  33.             listofsongs.append(files)
  34.  
  35.  
  36.     pygame.mixer.init()
  37.     pygame.mixer.music.load(listofsongs[0])
  38.     #pygame.mixer.music.play()
  39.  
  40. directorychooser()
  41.  
  42. def updatelabel():
  43.     global index
  44.     global songname
  45.     v.set(realnames[index])
  46.     #return songname
  47.  
  48.  
  49.  
  50. def nextsong(event):
  51.     global index
  52.     index += 1
  53.     pygame.mixer.music.load(listofsongs[index])
  54.     pygame.mixer.music.play()
  55.     updatelabel()
  56.  
  57. def prevsong(event):
  58.     global index
  59.     index -= 1
  60.     pygame.mixer.music.load(listofsongs[index])
  61.     pygame.mixer.music.play()
  62.     updatelabel()
  63.  
  64.  
  65. def stopsong(event):
  66.     pygame.mixer.music.stop()
  67.     v.set("")
  68.     #return songname
  69.  
  70.  
  71. label = Label(root,text='Music Player')
  72. label.pack()
  73.  
  74. listbox = Listbox(root)
  75. listbox.pack()
  76.  
  77. #listofsongs.reverse()
  78. realnames.reverse()
  79.  
  80. for items in realnames:
  81.     listbox.insert(0,items)
  82.  
  83. realnames.reverse()
  84. #listofsongs.reverse()
  85.  
  86.  
  87. nextbutton = Button(root,text = 'Next Song')
  88. nextbutton.pack()
  89.  
  90. previousbutton = Button(root,text = 'Previous Song')
  91. previousbutton.pack()
  92.  
  93. stopbutton = Button(root,text='Stop Music')
  94. stopbutton.pack()
  95.  
  96.  
  97. nextbutton.bind("<Button-1>",nextsong)
  98. previousbutton.bind("<Button-1>",prevsong)
  99. stopbutton.bind("<Button-1>",stopsong)
  100.  
  101. songlabel.pack()
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. root.mainloop()
Add Comment
Please, Sign In to add comment