0

I'm making an mp3 player in Python using tkinter and pygame. I'm completely new to coding and this in one of the first projects i'm working on. This is learning by doing. I'm trying to get the pause button to pause and unpause. All it does now is pause.

Can I use an if else statement for this? I have google back and forward for two days and tried many different solutions, but none of them have worked. This is what the code looks like now.

self.pauseButton = Button(self, text = 'Pause', command = self.pause)

def pause(self):
   pygame.mixer.music.pause()
   pygame.mixer.music.unpause()
mzjn
  • 48,958
  • 13
  • 128
  • 248
Atlefar
  • 3
  • 2

1 Answers1

0

You can use the text of the button for your advantage.

self.toggleVolumeButton = Button(self, text = 'Pause', command = self.toggleVolume)

def toggleVolume(self):
    if self.toggleVolumeButton['text'] == 'Pause':
        pygame.mixer.music.pause()
        self.toggleVolumeButton['text'] = 'Unpause'

    elif self.toggleVolumeButton['text'] == 'Unpause':
        pygame.mixer.music.unpause()
        self.toggleVolumeButton['text'] = 'Pause'

About accessing the text of a button you can use any of the methods from this question. I chose dictionary one.

As you can guess, there are multiple ways of accomplishing this task. This is just one of the ways.

Lafexlos
  • 7,618
  • 5
  • 38
  • 53