PyQt5样式表动画

2024-03-29 10:21:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用PyQt5构建一个带有多个按钮的应用程序。 我要完成的是为我的一些按钮创建一个闪烁的背景色(黄红色)。

btn1.setStyleSheet("background-color: green; color: red; font-weight: 800; font-size: 22")
tobyte = 'styleSheet'
a = bytearray(tobyte, 'utf-8')
animation = QtCore.QPropertyAnimation(' + 'btn' + str(yy) + ', a)
animation.setDuration(1000)
animation.setLoopCount(1000)
animation.setStartValue("background-color: yellow; color: red; font-weight: 800; font-size: 22")
animation.setEndValue("background-color: red; color: red; font-weight: 800; font-size: 22")
animation.start()

动画开始(移除预定义的绿色背景),但不会将按钮的背景颜色更改为黄色或红色。

有什么想法吗?


Tags: 应用程序sizered按钮pyqt5colorbackground背景