【发布时间】:2019-10-02 16:15:44
【问题描述】:
我需要帮助通过更改 Q 按钮的背景颜色来创建简单的“闪烁”效果。我想如果我能足够快地改变两种颜色之间的背景颜色,我就可以产生这种闪烁效果。但是,虽然我可以将背景颜色设置为一种颜色,但我不知道如何在两种颜色之间快速切换。我尝试使用循环,但我的输出 GUI 只保留一种颜色。我是这类东西的初学者,所以我可能缺少一个简单的解决方案。
我有所有必要的包和所有东西,所以为了简单起见,我只包括了处理背景颜色的按钮部分,这就是我认为我的问题所在。
self.powerup_button = QtWidgets.QPushButton(self.centralwidget)
count = 0
while count < 100:
self.powerup_button.setStyleSheet("background-color: none")
count = count + 1
self.powerup_button.setStyleSheet("background-color: green")
count = count + 1
我以为while循环会让按钮在两种颜色之间切换,创造出我想要的闪烁效果,但我错了。
【问题讨论】:
-
你在改变颜色后尝试过使用 self.powerup_button.repaint() 或 self.powerup_button.update() 吗?
标签: python user-interface pyqt5 qpushbutton