PyQt5 的动画的例子

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

app = QApplication(sys.argv)

window = QMainWindow()
window.show()
animation = QPropertyAnimation(window, b"geometry")
animation.setDuration(10000)
animation.setStartValue(QRect(0, 0, 100, 30))
#animation.setKeyValueAt(0.5, QRect(240, 240, 100, 30));
animation.setEndValue(QRect(250, 250, 100, 30))
# animation.setEasingCurve(QEasingCurve.OutBounce)
animation.start()

sys.exit(app.exec_())
# -*- coding: utf-8 -*-

"""
    【简介】
     动画分组
    
    
"""

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

app = QApplication(sys.argv)

window = QMainWindow()
window.show()
window2 = QMainWindow()
window2.show()

animation = QPropertyAnimation(window, b"geometry")
animation2 = QPropertyAnimation(window2, b"geometry")

group = QParallelAnimationGroup()

animation.setDuration(10000)
animation.setStartValue(QRect(0, 0, 100, 30))
animation.setEndValue(QRect(250, 250, 100, 30))
animation.setEasingCurve(QEasingCurve.OutBounce)

animation2.setDuration(10000)
animation2.setStartValue(QRect(250, 150, 100, 30))
animation2.setEndValue(QRect(850, 250, 100, 30))
animation2.setEasingCurve(QEasingCurve.CosineCurve)

group.addAnimation(animation)
group.addAnimation(animation2)
group.start()

sys.exit(app.exec_())
# -*- coding: utf-8 -*-

"""
    【简介】
    动画的效果改变窗体大小
    
    
"""

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

class ani(QWidget):
    def __init__(self):
        super(ani, self).__init__()
        self.OrigHeight = 50
        self.ChangeHeight = 150
        # 在X=500, Y=400 , Length=150 ,   Height=50
        self.setGeometry(QRect(500, 400, 150, self.OrigHeight)) 
        self.btn = QPushButton( '展开', self)
        self.btn.setGeometry(10, 10, 60, 35)
        self.machine = QStateMachine()
        self.btn.clicked.connect(self.change)         

    # 动画效果修改窗体大小
    def change(self):
        CurrentHeight = self.height()
        if self.OrigHeight == CurrentHeight:
            startHeight = self.OrigHeight
            endHeight = self.ChangeHeight
            self.btn.setText( '收缩')
        else:
            startHeight = self.ChangeHeight
            endHeight = self.OrigHeight
            self.btn.setText( '展开')
            
        self.animation = QPropertyAnimation(self,   b'geometry' )        
        self.animation.setDuration(800)
        self.animation.setStartValue(QRect(500, 400, 150, startHeight))
        self.animation.setEndValue(QRect(500, 400, 150, endHeight))
        self.animation.start()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = ani()
    window.show()
    sys.exit(app.exec_())
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容