PYQT5的资源文件或资源导入的故障?
我是与PYQT合作进行GUI开发的新手。作为其中一项培训的教程,我要开发一个电话拨号程序,该电话基本上只是显示一个数字板,并在按下时制作适当的拨号音调。这涉及导入包含12个音调的资源文件。我从互联网下载了音调并进行了测试。他们都可以正常工作。但是,在我创建资源文件并使用pyrcc5转换后,音调不播放。我从教程中复制了资源。我想知道是否有人可以帮助我调试这个问题。我还没有在网上看到任何显示类似问题的东西。
如果有人可以帮助我附加文件,我也可以将资源文件添加到问题中。
这是我的代码的副本,尽管它似乎并不是问题:
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtMultimedia as qtmm
import resources1
class SoundButton(qtw.QPushButton):
def __init__(self, wav_file, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wav_file = wav_file
self.player = qtmm.QSoundEffect()
self.player.setSource(qtc.QUrl.fromLocalFile(wav_file))
self.clicked.connect(self.player.play)
class MainWindow(qtw.QMainWindow):
def __init__(self):
"""MainWindow constructor.
This widget will be our main window.
We'll define all the UI components in here.
"""
super().__init__()
# Main UI code goes here
dialpad = qtw.QWidget()
self.setCentralWidget(dialpad)
dialpad.setLayout(qtw.QGridLayout())
for i, symbol in enumerate('123456789*0#'):
button = SoundButton(f':/dtmf/{symbol}.wav', symbol)
row = i // 3
column = i % 3
dialpad.layout().addWidget(button, row, column)
# End main UI code
self.show()
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
# it's required to save a reference to MainWindow.
# if it goes out of scope, it will be destroyed.
mw = MainWindow()
sys.exit(app.exec())
谢谢您的帮助
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论