pyqt5 平移动画

文章目录

        • 1、实例展示
        • 2、代码逻辑实现

1、实例展示

pyqt5 平移动画_第1张图片

2、代码逻辑实现

import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QPropertyAnimation, QSequentialAnimationGroup, QRect, QAbstractAnimation, QPoint
from PyQt5.QtWidgets import QApplication, QWidget, QLabel


class Demo(QWidget):
    def __init__(self):
        super(Demo, self).__init__()
        self.resize(700, 500)
        self.wid = 94
        self.hig = 135
        self.time = 3000
        self.hposition = 200
        self.plane = QLabel(self)
        self.plane.resize(self.wid, self.hig)
        self.plane.setPixmap(QPixmap('qq.png').scaled(self.plane.size()))


        self.animation = QPropertyAnimation(self.plane, b'pos')
        self.animation.setDuration(self.time)
        self.animation.setStartValue(QPoint(0, self.hposition))
        self.animation.setEndValue(QPoint(200, self.hposition))
        self.animation.setLoopCount(1)
        self.animation.finished.connect(self.animationFinished)
        self.animation.start()

    def animationFinished(self):
        print("animation finished")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())

文章参考:
《快速掌握PyQt5》第三十二章 动画

你可能感兴趣的:(PyQt5)