PYQT5的资源文件或资源导入的故障?

发布于 2025-02-10 17:23:27 字数 1844 浏览 2 评论 0 原文

我是与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())

谢谢您的帮助

I'm new to working with PyQt for GUI development. As a tutorial for one of the trainings, I'm to develop a phone dialer, which basically just displays a number pad and makes the appropriate dial tones when pressed. This involves importing a resource file that contains the 12 tones. i downloaded the tones from the internet and tested them. They all work just fine. however after I create the resource file, and convert it using pyrcc5, the tones do not play. I've copied the resources.py from the tutorial and the dial pad works as expected. I'm wondering if anyone can help me debug this issue. I haven't seen anything online that shows a similar problem.

if someone can help me attach files, I can add the resource files to the question as well.

Here is a copy of my code although it doesn't appear to be the problem:

    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())

Thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文