我需要将这个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())
答案 0 :(得分:0)
由于你没有发布什么问题,我只解决了实例化QSound
时的问题,Qt5重新分配包以建立更好的组织,因此我们在{{1}中找到了QSound
}}
QtMultimedia