Home > Back-end >  Can one tell me how make music Shuffle function in python Tkinter?
Can one tell me how make music Shuffle function in python Tkinter?

Time:08-15

how to play the selected randomised song next without passing it to the play music function

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

CodePudding user response:

Consider the following example using the shuffle function from random

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

This will return

['three', 'four', 'two', 'one']

CodePudding user response:

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)
  • Related