Home > Mobile >  Python Playsound not playing any sound when compiled into an .exe file
Python Playsound not playing any sound when compiled into an .exe file

Time:12-20

I'm trying to create a digital soundboard that can play object-defined sounds using tkinter and the playsound module. When I'm testing it via VS code, it works without any problems. But after I compile it into an exe, the app works but there's no sound playing.

I tried changing my compilation mode from '--onefile' to '--onedir' in pyinstaller but it didn't work. I also place the sound files into the folder directory of the executable file, but to no avail. Could there be something wrong with my code?

my code:

import tkinter
from tkinter import *
from PIL import ImageTk, Image
from playsound import playsound

win = Tk()
win.geometry('500x500')
win.maxsize(500,500)
win.title('Alarm Button')

def alarm():
    playsound(r'Announcement.mp3')

btn_image = PhotoImage(file='BUTTON.png')
comp_logo = PhotoImage(file='aaaa.png')
Logo = Label(win, image = comp_logo).place(x=390, y=470)

Press_me = Button(win, image=btn_image, command=alarm, borderwidth = 0)
Press_me.place(x=45, y=15)

def handler(e):
    alarm()

win.bind('<Return>', handler)
win.mainloop()

CodePudding user response:

I tried it and it still works, maybe it's because of pyinstaller? Or you can try using auto-py-to-exe since it works for me and also easier to use: https://pypi.org/project/auto-py-to-exe/

Make sure that you use playsound 1.2.2 because it's more stable than the 1.3.0 version. You can do it by using:

pip uninstall playsound

Then:

pip install playsound==1.2.2

Also I see that you import tkinter 2 times? You should delete

import tkinter
  • Related