Anmol panchal
Anmol panchal

Reputation: 29

how to play mp3 files when a tkinter button is pushed?

I try importing the mp3play module but it says that it doesn't exist. I also don't know how to put mp3 files into the program.

For example:

f = mp3play.load('Sound.mp3'); play = lambda: f.play()

I dont know how to insert the mp3 file into the 'Sound.mp3'.

Upvotes: 0

Views: 1820

Answers (1)

Guillermo del Molino
Guillermo del Molino

Reputation: 48

First of all, here is the mp3play documentation page: https://pypi.org/project/mp3play/

You said that Python returned that the module didn't exist. Are you sure that you installed it correctly on your system. I would run pip install mp3play and verify that it is installed.

I would suggest putting the audio files in the same folder as your code, so that you can keep everything together. If you look at one of the very first example on the docs page I linked above, you can see that the load function takes one paremeter which is the file address. There, you would need to type the full adress of the file, so for example: C:\Documents and Settings\Michael\Desktop\music.mp3, which is the example in the docs page. I think that should solve your problem.

Your code should look something like this:

f = mp3play.load('FULL ADDRESS/Sound.mp3'); play = lambda: f.play()

Upvotes: 2

Related Questions