实现思路:
利用QTimer间隔0.5s交替设置按钮的qss样式

#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC
@license: None
@contact: JHC000abc@gmail.com
@file: board_window.py
@time: 2022/4/25 13:14
@desc:board_window.py
'''
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtCore import Qt, QTimer
from gui.ui import board

# 闪烁时间0.5s
Blink_time = 500


class BorderWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.ui = board.Ui_Form()
        self.ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAutoFillBackground(True)
        self.resize(300, 300)
        # 记录状态
        self.mode = 0
        self.change_status = QTimer()
        self.change_status.timeout.connect(self.change_box_color)
        self.change_status.start(Blink_time)

    def change_box_color(self):
        if self.mode==0:
            self.ui.pushButton.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_2.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_3.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_19.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_25.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_31.setStyleSheet("background-color: rgb(0,0,0);")

            self.ui.pushButton_5.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_10.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_15.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_21.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_27.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_33.setStyleSheet("background-color: rgb(0,0,0);")

            self.ui.pushButton_8.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_12.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_17.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_23.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_29.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_35.setStyleSheet("background-color: rgb(0,0,0);")


            self.ui.pushButton_4.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_9.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_14.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_20.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_26.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_32.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.ui.pushButton_6.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_11.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_16.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_22.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_28.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_34.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.ui.pushButton_7.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_13.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_18.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_24.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_30.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_36.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.mode=1
        else:
            self.ui.pushButton.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_2.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_3.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_19.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_25.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_31.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.ui.pushButton_5.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_10.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_15.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_21.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_27.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_33.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.ui.pushButton_8.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_12.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_17.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_23.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_29.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_35.setStyleSheet("background-color: rgb(255, 255, 255);")

            self.ui.pushButton_4.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_9.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_14.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_20.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_26.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_32.setStyleSheet("background-color: rgb(0,0,0);")

            self.ui.pushButton_6.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_11.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_16.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_22.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_28.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_34.setStyleSheet("background-color: rgb(0,0,0);")

            self.ui.pushButton_7.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_13.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_18.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_24.setStyleSheet("background-color: rgb(0,0,0);")
            self.ui.pushButton_30.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.ui.pushButton_36.setStyleSheet("background-color: rgb(0,0,0);")

            self.mode = 0




if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    myForm = BorderWindow()
    myForm.show()
    sys.exit(app.exec())

在这里插入图片描述
在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐