In this program I'm playing a sound when my pushbutton is clicked and then changing the label here's my code :
from PySide6.QtCore import (QCoreApplication,QMetaObject, QRect, Qt)
from PySide6.QtGui import (QFont)
from PySide6.QtWidgets import (QApplication,QMainWindow,QLabel,QPushButton,QWidget)
import winsound
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(230, 130)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
font = QFont()
font.setFamilies([u"Times New Roman"])
font.setPointSize(13)
font.setBold(True)
self.pushButton = QPushButton(self.centralwidget)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(30, 20, 171, 51))
self.pushButton.setFont(font)
self.pushButton.clicked.connect(self.buttonclicked)
self.label = QLabel(self.centralwidget)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(30, 80, 171, 31))
self.label.setFont(font)
self.label.setAlignment(Qt.AlignCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"click me ;)", None))
def buttonclicked(self):
winsound.PlaySound(r"C:\Windows\Media\speech on.wav", winsound.SND_ALIAS)
self.label.setText("sound played")
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
program = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(program)
program.show()
sys.exit(app.exec())
And when I press my button it becomes pushed and when playing sound is finished it changes the label I tried changing the lines
def buttonclicked(self):
self.label.setText("sound played")
winsound.PlaySound(r"C:\Windows\Media\speech on.wav", winsound.SND_ALIAS)
but it's not working I mean that for 3 seocnds(period of time that the sound is playing) the button is pushed and I want to avoid it here's the photo for 2-3 seconds I mean that I want playing sound outside of my program because when the sound is playing it just stops everything