Attempting to finish up the Drum Kit in Python!!!!
What it does so far…
ADDING A PLAY/PAUSE BUTTON
First, create the button in the main loop, and place it on the screen.
play_pause = py.draw.rect(screen, grey, [50, HEIGHT - 150, 200, 100], 0, 5)
play_text = label_font.render('Play/Pause', True, white)
screen.blit(play_text, (70, HEIGHT - 130))
After that, create a new variable called “mediumFont” as in indicator if the program is playing or not. This will be connected to “play_text2”.
if playing:
play_text2 = mediumFont.render('Playing', True, darkGrey)
else:
play_text2 = mediumFont.render('Paused', True, darkGrey)
screen.blit(play_text2, (70, HEIGHT - 100))
The “play_text2” will have “Playing” or “Pausing” shown on screen when the “Play/Pause” button is pressed.
So… we made the button show up on screen, but we haven’t made it actually work yet.
Down into where the buttons pressed on your keyboard are called, make a new event type of ‘MOUSEBUTTONUP”. This will make the program able to play and pause when the button is clicked.
if event.type == py.MOUSEBUTTONUP:
if play_pause.collidepoint(event.pos):
if playing:
playing = False
elif not playing:
playing = True
RESULTS: