I'd really like to know the simplest way to implement music while people play the game I created, and for sounds to play during certain events. (such as dying)

Recommended Answers

You are running the program from command line or double click the file, don't you?

Jump to Post

All 3 Replies

I'm having trouble getting the music to stop and the application to close.

Near the head of my program, I have

pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load("theme.mp3")
pygame.mixer.music.play(loops=0, start=0.0)

I inserted

root.protocol("WM_DELETE_WINDOW", endOfGame)

right before my root.mainloop, and end of game is:

def endOfGame():
    pygame.mixer.stop()
    root.destroy()

No matter what I do, it either doesn't stop until 20 seconds after the program is killed, or doesn't close when I hit the X.

You are running the program from command line or double click the file, don't you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.