1 Star 0 Fork 0

fanyangchu/PythonCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Mp3_media_player.py 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
Jayant123-Joker 提交于 2020-09-30 21:17 . Update Mp3_media_player.py
# 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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanych/pythoncode.git
git@gitee.com:fanych/pythoncode.git
fanych
pythoncode
PythonCode
master

搜索帮助