我正在使用 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()
Run Code Online (Sandbox Code Playgroud)
动画开始(删除预定义的绿色背景),但不会将按钮的背景颜色更改为黄色或红色。
有任何想法吗?