有人能告诉我如何在python Tkinter中实现音乐Shuffle功能吗



如何在不将所选随机歌曲传递给播放音乐功能的情况下播放下一首歌曲

def Shuffle():
song_box0= list(song_box.get('0','end'))
choosen= random.randint(0,len(song_box0))
songp= song_box0[choosen]

考虑以下使用随机的shuffle函数的示例

songs = ["one", "two", "three", "four"]
shuffle(songs)
print(songs)

这将返回

['three', 'four', 'two', 'one']
def shuffle():
#gets all the song in our playlist window from 0 to End in form of a list
song_box0= list(song_box.get('0','end'))
#a number say i from 0 to length of the list is choosen randomly
choosen=random.randint(0,len(song_box0))
# 'ith' number song of the list is choosen
songp=song_box0[choosen]
#directory of song is given
songp = f'C:/Users/bhowm/abc/musicplayer/songss/{songp}.mp3'
# that 'ith' song is loaded and played
pygame.mixer.music.load(songp)
pygame.mixer.music.play(loops=0)

最新更新