我不知道如何在不使用类的情况下让 tkinter 列表框在我的音乐播放器中播放连续的音频文件,我还不完全理解,因为我是 python 的新手。 我已经通过以下示例创建了一个事件,它在列表框中打印播放的歌曲和下一首歌曲,但我不知道如何从那里移动。
SONG_END = pygame.USEREVENT+1
pygame.mixer.music.set_endevent(SONG_END)
def check_event():
for event in pygame.event.get():
if event.type == SONG_END:
print('music end event')
for i in listbox.curselection():
nxt_song = listbox.get(i + 1)
print(nxt_song)
root.after(100, check_event)
def next_s ():
# i cant figure out how to proceed from here to
# get the nxt song and play it
pass
def play():
# activates the play button
current = listbox.get(ACTIVE)
playing_song['text'] = current # goes to a label displaying the current track name
mixer.music.load(current)
mixer.music.play()
# everything works as i want exept continuous play
# note that i dont want the player to have previous and next buttons
这和播放歌曲是一样的。你必须做
pygame.mixer.load(next_song)
pygame.mixer.play()
您还必须调整当前歌曲的值,以便它在列表中移动。
current = next_song