将pyside代码转换为pyqt5代码

Converting pyside code to pyqt5 code

我需要将此 PySide 代码转换为 PyQt5,因为大部分语法是相同的,所以这不是什么大问题。但是 运行 此代码存在某些问题。你能帮我把这个pyside代码转换成pyqt5吗?非常感谢

    import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWidgets import *

class Animation_area(QWidget):
    def __init__(self):
        QWidget.__init__(self, None)

        self.frame_no = 0
        self.images = [
            QImage("images/frame-" + str(i + 1) + ".png")
            for i in range(20)
        ]

        timer = QTimer(self)
        timer.timeout.connect(self.update_value)
        timer.start(50)
        self.pause = False

    def paintEvent(self, e):
        p = QPainter()
        p.begin(self)
        p.drawImage(QRect(0, 0, 320, 320), self.images[self.frame_no])
        p.end()

    def update_value(self):
        if not self.pause:
            self.frame_no += 1
            if self.frame_no >= 20:
                self.frame_no = 0
                QSound.play("sounds/rabbit_jump.wav")

            self.update()

    def PlayandPause(self):
        if self.pause == True:
            self.pause = False
        else:
            self.pause = True

class Simple_animation_window(QWidget):
    def __init__(self):
        QWidget.__init__(self, None)

        self.anim_area = Animation_area()

        layout = QVBoxLayout()
        layout.addWidget(self.anim_area)
        self.PlayandPauseButton = QPushButton("Pause")
        self.PlayandPauseButton.clicked.connect(self.clicked)
        layout.addWidget(self.PlayandPauseButton)

        self.setLayout(layout)
        self.setMinimumSize(330, 400)
    def clicked(self):
        self.anim_area.PlayandPause()
        if self.sender().text() == "Play":
            self.PlayandPauseButton.setText("Pause")
        else:
            self.PlayandPauseButton.setText("Play")

def main():
    app = QApplication(sys.argv)

    w = Simple_animation_window()
    w.show()

    return app.exec_()

if __name__ == "__main__":
    sys.exit(main())

因为你没有post问题是什么,我只解决了我在实例化时遇到的问题QSound,Qt5重新分配包以获得更好的组织所以我们发现QSoundQtMultimedia.

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


class Animation_area(QWidget):
    def __init__(self):
        QWidget.__init__(self, None)

        self.frame_no = 0
        self.images = [QImage("images/frame-" + str(i + 1) + ".png") for i in range(20)]

        timer = QTimer(self)
        timer.timeout.connect(self.update_value)
        timer.start(50)
        self.pause = False

    def paintEvent(self, e):
        p = QPainter(self)
        p.drawImage(QRect(0, 0, 320, 320), self.images[self.frame_no])

    def update_value(self):
        if not self.pause:
            self.frame_no += 1
            if self.frame_no >= 20:
                self.frame_no = 0
                QSound.play("sounds/rabbit_jump.wav")
            self.update()

    def PlayandPause(self):
        self.pause = not self.pause


class Simple_animation_window(QWidget):
    def __init__(self):
        QWidget.__init__(self, None)

        self.anim_area = Animation_area()

        layout = QVBoxLayout()
        layout.addWidget(self.anim_area)
        self.PlayandPauseButton = QPushButton("Pause")
        self.PlayandPauseButton.clicked.connect(self.clicked)
        layout.addWidget(self.PlayandPauseButton)

        self.setLayout(layout)
        self.setMinimumSize(330, 400)

    def clicked(self):
        self.anim_area.PlayandPause()
        if self.sender().text() == "Play":
            self.PlayandPauseButton.setText("Pause")
        else:
            self.PlayandPauseButton.setText("Play")


def main():
    app = QApplication(sys.argv)

    w = Simple_animation_window()
    w.show()

    return app.exec_()


if __name__ == "__main__":
    sys.exit(main())