天天看点

python制作动画为什么不动_为什么QPropertyAnimation动画不起作用?

我试图在按下按钮时生成动画,但在self.frame2返回大小0后,它不起作用:

这是一个例子:

python制作动画为什么不动_为什么QPropertyAnimation动画不起作用?

帧返回0后,动画不会再次执行:from PyQt5.QtWidgets import QMainWindow,QApplication

from PyQt5 import QtCore

from PyQt5 import uic

class Login(QMainWindow):

def __init__(self):

QMainWindow.__init__(self)

uic.loadUi("1.-Login.ui",self)

#Apariencia de Ventana

self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

self.setAttribute(QtCore.Qt.WA_NoSystemBackground,True)

self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)

#Botones

self.Ajustes.clicked.connect(self.animaAjustes)

self.ComboSuc.lineEdit().setAlignment(QtCore.Qt.AlignCenter)

self.animation = QtCore.QPropertyAnimation(self.frame2, b'size', self)

self.animation.setStartValue(QtCore.QSize(0,0))

self.animation.setEndValue(QtCore.QSize(145,443))

self.animation.setDuration(200)

self.animation.setDirection(QtCore.QAbstractAnimation.Forward)

def animaAjustes(self):

if self.frame2.width()!=0:

self.frame2.setGeometry(0,0,0,0)

else:

self.animation.start()

app = QApplication([])

l = Login()

l.show()

app.exec_()

在文件.ui在

^{pr2}$