愿意开发一种媒体播放器,当播放一首歌曲时会显示“歌词”,吉他和钢琴代码,但不知道如何开始。我从下面的代码开始,当第一次按下add_play_list按钮时,这给了我“ filedialog not defined”错误,在第二次运行时该错误消失了。代码可以播放文件夹中的歌曲,但是直到播放完所有歌曲后,根帧窗口才“无响应”。我该如何解决这些问题?如何在标签中添加歌词和吉他代码?您的指导会有所帮助。谢谢。
import os
from tkinter import *
import tkinter.filedialog
import mutagen
import pygame
root= Tk()
root.title("AVPlayer")
root.geometry("500x250")
top_frame= Frame(root, bg='red')
top_frame.pack(fill=BOTH, expand=True)
playlist= Listbox(top_frame, relief='flat',
font=("Arial",8),fg='white', bg='red')
playlist.pack( fill=BOTH, expand=True,
padx=10, pady=10)
vscroll=Scrollbar(playlist)
vscroll.pack(side=RIGHT, fill=BOTH)
vscroll.config(command=playlist.yview)
playlist.config(yscrollcommand=vscroll.set)
midl_frame=Frame(root, bg="red", height=50)
midl_frame.pack(fill=BOTH)
add_play_list= Button(midl_frame,text="+",
bg='red', font=('Arial', 15),
relief='flat', borderwidth=2, fg='white',
command=playlistitems)
add_play_list.pack(padx=10, side=LEFT)
nextbtn=Button(midl_frame, text='>|',font=
('Arial',15),bg='red',fg='white',
relief='flat',borderwidth=2)
nextbtn.pack(side=RIGHT, padx=10)
prvsbtn=Button(midl_frame, text='|<',font=
('Arial',15),bg='red',fg='white',
relief='flat',borderwidth=2)
prvsbtn.pack(side=RIGHT, padx=10)
pausebtn=Button(midl_frame, text='||',
bg='red', font=('Arial',15), relief='flat',
borderwidth=2, fg='white')
pausebtn.pack(side=RIGHT, padx=10)
playbtn= Button(midl_frame,text='>',
bg='red', font=('Arial',15), relief='flat',
borderwidth=2, fg='white',
command=playaudio)
playbtn.pack(side=RIGHT, padx=10)
songlist=[]
def playlistitems(event):
global flpath
flpath= filedialog.askdirectory()
for i in os.listdir(flpath):
if i.endswith(".mp3"):
title=
mutagen.File(os.path.join(flpath,i))
playlist.insert(END,title['TIT2'][0])
songlist.append(i)
def playaudio(event):
for x in songlist:
pygame.mixer.init()
pygame.mixer.music.load
(os.path.join(flpath,x))
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(100)
root.mainloop()