0

I'm new to Python3 and I tried to use pygame library. Firstly I tried to play .mp3 file using pygame.mixer with following code:

import pygame
from pygame import mixer
mixer.init()
mixer.music.load('some.mp3')
mixer.music.play()

I tried to run this code but it just went through it and didn't do anything but showed pygame welcome message. Not even a single error. Then I tried to run this code by writing every single line in console and somehow it worked.


Similar thing happens with this code:

from pygame import *
init()
while going:
    for e in event.get():
        if e.type == QUIT:
            going = False
        if e.type == KEYDOWN:
            if e.key == K_ESCAPE:
                going = False
    print("work")

I copied it from official pygame eventlist example and while the example runs as it's intended to it doesn't work when I use only part showed above.
What am I doing wrong here?

  • https://stackoverflow.com/questions/7746263/how-play-mp3-with-pygame – Rohan Jul 17 '18 at 16:42
  • Possible duplicate of [how play mp3 with pygame](https://stackoverflow.com/questions/7746263/how-play-mp3-with-pygame) – skrx Jul 17 '18 at 18:18
  • It's not duplicate. I tried methods from this question and it still doesn't work. What is more, it seems like the program exits before playing the music or it crashes while trying cause I added print at the end of the code and it didn't show up – Tomek Tendera Jul 19 '18 at 13:49

1 Answers1

0

You haven't told your program to write anything so it hasn't.

You need to to add print statements if you want your Python program to write something to your console.

Here's an example: print("Hello World")

You should obviously place the exact response you are looking to get inside the print statement.

I Stand With Israel
  • 1,971
  • 16
  • 30