Skip to content Skip to sidebar Skip to footer

I Am Making A Mp3 Player , And I Need A Forward Button To It But Cant Seem To Figure It Out

So, for playing the song, the code I have is: def play_song(*args): idx = song_list.curselection()[0] song = song_dict[idx][1] pygame.mixer.music.load(song) pygam

Solution 1:

Looked like you wanted me to take a look here, I think this is simple. Get the current selection and add one to the current selection and clear the current selection, then set the current selection to the new selection then load and play the song. So the function would be like:

defnext_song():
    try:
        idx = song_list.curselection()[0] + 1# The initial curselection + 1
        song_list.selection_clear(0,'end') # Clear the old selection
        song_list.selection_set(idx) # Set selection to new item
        song_list.activate(idx) # Set the entire focus to new item?
        
        song = song_dict[idx][1] # Get the corresponding song from the dictionary 
        pygame.mixer.music.load(song) # Load the song
        pygame.mixer.music.play(loops=0) # Play the songexcept IndexError: # If no item selected pass# Ignore the error

Example: So if the current selection is 1 then it removes 1 and makes it 2 and sets the current selection to 2 and activates it(the underline by default) and proceeds like this each time button is pressed.

Post a Comment for "I Am Making A Mp3 Player , And I Need A Forward Button To It But Cant Seem To Figure It Out"