代码拉取完成,页面将自动刷新
# its very amazing
import os
from tkinter.filedialog import askdirectory
import pygame
from mutagen.id3 import ID3
from tkinter import *
root = Tk()
root.minsize(300,300)
listofsongs = []
realnames = []
v = StringVar()
songlabel = Label(root,textvariable=v,width=35)
index = 0
def directorychooser():
directory = askdirectory()
os.chdir(directory)
for files in os.listdir(directory):
if files.endswith(".mp3"):
realdir = os.path.realpath(files)
audio = ID3(realdir)
realnames.append(audio['TIT2'].text[0])
listofsongs.append(files)
pygame.mixer.init()
pygame.mixer.music.load(listofsongs[0])
#pygame.mixer.music.play()
directorychooser()
def updatelabel():
global index
global songname
v.set(realnames[index])
#return songname
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
label = Label(root,text='Music Player')
label.pack()
listbox = Listbox(root)
listbox.pack()
#listofsongs.reverse()
realnames.reverse()
for items in realnames:
listbox.insert(0,items)
realnames.reverse()
#listofsongs.reverse()
nextbutton = Button(root,text = 'Next Song')
nextbutton.pack()
previousbutton = Button(root,text = 'Previous Song')
previousbutton.pack()
stopbutton = Button(root,text='Stop Music')
stopbutton.pack()
nextbutton.bind("<Button-1>",nextsong)
previousbutton.bind("<Button-1>",prevsong)
stopbutton.bind("<Button-1>",stopsong)
songlabel.pack()
root.mainloop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。