0

I use python3.5, and I made a GUI with pyqt5. In that GUI, when I push the button, I can play back a music with wav file. This is the code.

import sys
from PyQt5 import QtCore, QtWidgets, QtMultimedia
from PyQt5.QtGui import QColor
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class Window(QtWidgets.QWidget):
    def __init__(self):
        super(Window, self).__init__()
        self.setWindowTitle("sound")
        self.setGeometry(500,300,100,100)

        btn = QPushButton(self)
        btn.setIcon(self.style().standardIcon(getattr(QStyle,"SP_MediaPlay")))
        btn.setToolTip('音が出ます')
        btn.move(50, 25)  
        btn.clicked.connect(self.handlePlay)

        self.mediaPlayer = QtMultimedia.QMediaPlayer(self)
        sound=QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile("Magia.wav"))
        self.mediaPlayer.setMedia(sound)

        self.show()


    def handlePlay(self):
        self.mediaPlayer.stop()
        self.mediaPlayer.play()


if __name__ == '__main__':

    app = QtWidgets.QApplication(sys.argv)
    window = Window()
    sys.exit(app.exec_())

By this code, you can make a GUI like this.

image

When you push the button, you can play back a music which is wav file. And I changed this python code into exe file by pyinstaller. But in the exe file, when I push the button, nothing happens. My OS environment is windows8.1 and 64bits.

toma
  • 147
  • 1
  • 9
  • 1
    Run it from the CMD and indicate if you have an error message. – eyllanesc May 28 '18 at 13:50
  • Thenk you for your comment. The code run in python successfully, but it doesn't run in exe file. And no error message is shown. "Run it from the CMD" means that I run the exe file from the CMD? – toma May 29 '18 at 00:39
  • try to use the full path for your sound file. In case it's working that way, follow this question about [Bundling data files with PyInstaller](https://stackoverflow.com/q/7674790/4464653) – Skandix May 30 '18 at 09:14
  • I tried full path, but it doesn't play sound. – toma Jun 01 '18 at 15:26

0 Answers0