qt制作闪烁棋盘

得意时要看淡,失意时要看开。不论得意失意,切莫大意;不论成功失败,切莫止步。志得意满时,需要的是淡然,给自己留一条退路;失意落魄时,需要的是泰然,给自己觅一条出路qt制作闪烁棋盘,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

实现思路:
利用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())

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156923.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!