Python-桌面计时器程序设计

该程序是我个人去年学习之初练习设计,程序功能并没有很完善和简便。设计想法是为了能够有一个可观性高的时间报时器,程序设计耗时2天,程序分成三个部分:主窗体、设置窗口、运行程序。

效果展示图

Python-桌面计时器程序设计_第1张图片
Python-桌面计时器程序设计_第2张图片

Python-桌面计时器程序设计_第3张图片

功能

· 正/反计时功能

· 到时提醒/关闭

· 时间显示

· 色彩变换

实现说明

通过time.time()API获取程序运行的初始时间,当时间增加时,程序设置的时间进行加减。而时间读取的电脑硬件时间,随着系统变更。

主启动文件

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget
from untitled import Ui_Form
import sys


class Mywindow(QWidget, Ui_Form):
    def __init__(self):
        super().__init__()
        self.timer_id = 0
        self.setupUi(self)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        #设置该控件父类为self
        self.pushButton.setParent(self)
        self.pushButton_2.setParent(self)
        self.pushButton_3.setParent(self)


    def mousePressEvent(self, evt):
        self.mouse_x = evt.globalX()
        self.mouse_y = evt.globalY()

        self.origin_x = self.x()
        self.origin_y = self.y()


    def mouseMoveEvent(self, evt):
        move_x = evt.globalX() - self.mouse_x
        move_y = evt.globalY() - self.mouse_y

        dest_x = self.origin_x + move_x
        dest_y = self.origin_y + move_y
        self.move(dest_x, dest_y)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    Windows = Mywindow()
    Windows.show()
    sys.exit(app.exec_())
设置窗体设计
def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(278, 146)
        Dialog.setMaximumSize(QtCore.QSize(278, 146))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../../../../../Python34/Lib/site-packages/PyQt5/examples/draganddrop/draggableicons/images/boat.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Dialog.setWindowIcon(icon)
        self.tabWidget = QtWidgets.QTabWidget(Dialog)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 281, 141))
        self.tabWidget.setMinimumSize(QtCore.QSize(281, 141))
        self.tabWidget.setMaximumSize(QtCore.QSize(281, 141))
        self.tabWidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.tabWidget.setTabPosition(QtWidgets.QTabWidget.North)
        self.tabWidget.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.tabWidget.setElideMode(QtCore.Qt.ElideNone)
        self.tabWidget.setDocumentMode(True)
        self.tabWidget.setTabsClosable(False)
        self.tabWidget.setMovable(False)
        self.tabWidget.setTabBarAutoHide(False)
        self.tabWidget.setObjectName("tabWidget")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.tab)
        self.lineEdit_2.setGeometry(QtCore.QRect(120, 30, 31, 31))
        self.lineEdit_2.setMaxLength(2)
        self.lineEdit_2.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.lineEdit = QtWidgets.QLineEdit(self.tab)
        self.lineEdit.setGeometry(QtCore.QRect(60, 30, 31, 31))
        self.lineEdit.setInputMask("")
        self.lineEdit.setMaxLength(2)
        self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit.setDragEnabled(False)
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QtWidgets.QPushButton(self.tab)
        self.pushButton.setGeometry(QtCore.QRect(100, 80, 81, 31))
        self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
        self.pushButton.setObjectName("pushButton")
        self.label = QtWidgets.QLabel(self.tab)
        self.label.setGeometry(QtCore.QRect(70, 10, 16, 16))
        self.label.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.label.setObjectName("label")
        self.label_3 = QtWidgets.QLabel(self.tab)
        self.label_3.setGeometry(QtCore.QRect(190, 10, 16, 16))
        self.label_3.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.label_3.setObjectName("label_3")
        self.lineEdit_3 = QtWidgets.QLineEdit(self.tab)
        self.lineEdit_3.setGeometry(QtCore.QRect(180, 30, 31, 31))
        self.lineEdit_3.setMaxLength(2)
        self.lineEdit_3.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.label_2 = QtWidgets.QLabel(self.tab)
        self.label_2.setGeometry(QtCore.QRect(130, 10, 16, 16))
        self.label_2.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.label_2.setObjectName("label_2")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tabWidget.addTab(self.tab, icon1, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.checkBox_3 = QtWidgets.QCheckBox(self.tab_2)
        self.checkBox_3.setGeometry(QtCore.QRect(20, 70, 131, 16))
        self.checkBox_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.checkBox_3.setChecked(False)
        self.checkBox_3.setObjectName("checkBox_3")
        self.checkBox_2 = QtWidgets.QCheckBox(self.tab_2)
        self.checkBox_2.setGeometry(QtCore.QRect(20, 40, 111, 16))
        self.checkBox_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.checkBox_2.setChecked(True)
        self.checkBox_2.setAutoRepeat(False)
        self.checkBox_2.setAutoExclusive(False)
        self.checkBox_2.setTristate(False)
        self.checkBox_2.setObjectName("checkBox_2")
        self.checkBox = QtWidgets.QCheckBox(self.tab_2)
        self.checkBox.setGeometry(QtCore.QRect(20, 10, 61, 21))
        self.checkBox.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.checkBox.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.checkBox.setAcceptDrops(True)
        self.checkBox.setAutoFillBackground(False)
        self.checkBox.setCheckable(True)
        self.checkBox.setChecked(True)
        self.checkBox.setObjectName("checkBox")
        self.pushButton_2 = QtWidgets.QPushButton(self.tab_2)
        self.pushButton_2.setGeometry(QtCore.QRect(190, 10, 71, 31))
        self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
        self.pushButton_2.setObjectName("pushButton_2")
        self.checkBox_4 = QtWidgets.QCheckBox(self.tab_2)
        self.checkBox_4.setGeometry(QtCore.QRect(100, 10, 71, 21))
        self.checkBox_4.setObjectName("checkBox_4")
        self.label_4 = QtWidgets.QLabel(self.tab_2)
        self.label_4.setGeometry(QtCore.QRect(240, 100, 41, 16))
        self.label_4.setObjectName("label_4")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("3.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tabWidget.addTab(self.tab_2, icon2, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.pushButton_3 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_3.setGeometry(QtCore.QRect(100, 24, 21, 21))
        self.pushButton_3.setStyleSheet("background-color: rgb(170, 0, 0);")
        self.pushButton_3.setText("")
        self.pushButton_3.setObjectName("pushButton_3")
        
        self.pushButton_4 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_4.setGeometry(QtCore.QRect(130, 24, 21, 21))
        self.pushButton_4.setStyleSheet("background-color: rgb(0, 255, 0);")
        self.pushButton_4.setText("")
        self.pushButton_4.setObjectName("pushButton_4")
        
        self.pushButton_5 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_5.setGeometry(QtCore.QRect(190, 24, 21, 21))
        self.pushButton_5.setStyleSheet("background-color: rgb(255, 0, 0);")
        self.pushButton_5.setText("")
        self.pushButton_5.setObjectName("pushButton_5")
        self.pushButton_6 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_6.setGeometry(QtCore.QRect(160, 24, 21, 21))
        self.pushButton_6.setStyleSheet("background-color: rgb(0, 0, 127);")
        self.pushButton_6.setText("")
        self.pushButton_6.setObjectName("pushButton_6")
        self.pushButton_7 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_7.setGeometry(QtCore.QRect(220, 24, 21, 21))
        self.pushButton_7.setStyleSheet("background-color: rgb(0, 255, 255);")
        self.pushButton_7.setText("")
        self.pushButton_7.setObjectName("pushButton_7")
        self.pushButton_8 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_8.setGeometry(QtCore.QRect(130, 54, 21, 21))
        self.pushButton_8.setStyleSheet("background-color: rgb(255, 255, 0);")
        self.pushButton_8.setText("")
        self.pushButton_8.setObjectName("pushButton_8")
        self.pushButton_9 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_9.setGeometry(QtCore.QRect(190, 54, 21, 21))
        self.pushButton_9.setStyleSheet("background-color: rgb(0, 0, 0);")
        self.pushButton_9.setText("")
        self.pushButton_9.setObjectName("pushButton_9")
        self.pushButton_10 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_10.setGeometry(QtCore.QRect(100, 54, 21, 21))
        self.pushButton_10.setStyleSheet("background-color: rgb(85, 0, 127);")

        
        self.pushButton_10.setText("")
        self.pushButton_10.setObjectName("pushButton_10")
        self.pushButton_11 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_11.setGeometry(QtCore.QRect(160, 54, 21, 21))
        self.pushButton_11.setStyleSheet("background-color: rgb(255, 85, 0);")
        self.pushButton_11.setText("")
        self.pushButton_11.setObjectName("pushButton_11")
        self.pushButton_12 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_12.setGeometry(QtCore.QRect(220, 54, 21, 21))
        self.pushButton_12.setStyleSheet("background-color: rgb(255, 170, 255);")
        self.pushButton_12.setText("")
        self.pushButton_12.setObjectName("pushButton_12")
        self.pushButton_13 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_13.setGeometry(QtCore.QRect(130, 84, 21, 21))
        self.pushButton_13.setStyleSheet("background-color: rgb(85, 0, 255);")
        self.pushButton_13.setText("")
        self.pushButton_13.setObjectName("pushButton_13")
        self.pushButton_14 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_14.setGeometry(QtCore.QRect(190, 84, 21, 21))
        self.pushButton_14.setStyleSheet("background-color: rgb(85, 0, 0);")
        self.pushButton_14.setText("")
        self.pushButton_14.setObjectName("pushButton_14")
        self.pushButton_15 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_15.setGeometry(QtCore.QRect(100, 84, 21, 21))
        self.pushButton_15.setStyleSheet("background-color: rgb(0, 85, 0);")
        self.pushButton_15.setText("")
        self.pushButton_15.setObjectName("pushButton_15")
        self.pushButton_16 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_16.setGeometry(QtCore.QRect(160, 84, 21, 21))
        self.pushButton_16.setStyleSheet("background-color: rgb(170, 170, 127);")
        self.pushButton_16.setText("")
        self.pushButton_16.setObjectName("pushButton_16")
        self.pushButton_17 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_17.setGeometry(QtCore.QRect(220, 84, 21, 21))
        self.pushButton_17.setStyleSheet("background-color: rgb(0, 0, 255);")
        self.pushButton_17.setText("")
        self.pushButton_17.setObjectName("pushButton_17")
        self.line = QtWidgets.QFrame(self.tab_3)
        self.line.setGeometry(QtCore.QRect(30, 0, 211, 20))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.line_2 = QtWidgets.QFrame(self.tab_3)
        self.line_2.setGeometry(QtCore.QRect(250, 14, 20, 91))
        self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.pushButton_18 = QtWidgets.QPushButton(self.tab_3)
        self.pushButton_18.setGeometry(QtCore.QRect(10, 30, 75, 71))
        self.pushButton_18.setText("")
        self.pushButton_18.setObjectName("pushButton_18")
        self.tabWidget.addTab(self.tab_3, "")

        self.retranslateUi(Dialog)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "SetNum@Lin"))
        self.lineEdit_2.setText(_translate("Dialog", "00"))
        self.lineEdit.setText(_translate("Dialog", "00"))
        self.pushButton.setText(_translate("Dialog", "设定"))
        self.label.setText(_translate("Dialog", "时"))
        self.label_3.setText(_translate("Dialog", "秒"))
        self.lineEdit_3.setText(_translate("Dialog", "00"))
        self.label_2.setText(_translate("Dialog", "分"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Dialog", "设定时间"))
        self.checkBox_3.setText(_translate("Dialog", "执行结束后关闭程序"))
        self.checkBox_2.setText(_translate("Dialog", "执行结束后提醒"))
        self.checkBox.setText(_translate("Dialog", "倒计时"))
        self.pushButton_2.setText(_translate("Dialog", "关闭程序"))
        self.checkBox_4.setText(_translate("Dialog", "时钟"))
        self.label_4.setText(_translate("Dialog", "@Lin"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Dialog", "配置"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("Dialog", "颜色"))
控制所有按钮链接对应的方法
def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.clicked.connect(self.click)
        self.pushButton_2.clicked.connect(self.Close)
        self.pushButton_3.clicked.connect(self.color_1)
        self.pushButton_4.clicked.connect(self.color_2)
        self.pushButton_5.clicked.connect(self.color_3)
        self.pushButton_6.clicked.connect(self.color_4)
        self.pushButton_7.clicked.connect(self.color_5)
        self.pushButton_8.clicked.connect(self.color_6)
        self.pushButton_9.clicked.connect(self.color_7)
        self.pushButton_10.clicked.connect(self.color_8)
        self.pushButton_11.clicked.connect(self.color_9)
        self.pushButton_12.clicked.connect(self.color_10)
        self.pushButton_13.clicked.connect(self.color_11)
        self.pushButton_14.clicked.connect(self.color_12)
        self.pushButton_15.clicked.connect(self.color_13)
        self.pushButton_16.clicked.connect(self.color_14)
        self.pushButton_17.clicked.connect(self.color_15)
        self.a = 0
记录程序启动时间(startTimer循环运行)
def startTime(self):
        self.pushButton.clicked.disconnect(self.startTime)
        self.now = time.localtime()
        self.start_time = int(time.time())
        self.a = 0
        
        tj[0] = 1
        self.timer_id = self.startTimer(200)
        self.pushButton.setIcon(self.icon_2)
        self.pushButton.clicked.connect(self.Stop)
程序暂停
def Stop(self):
        self.pushButton.clicked.disconnect(self.Stop)
        self.TimeEnd()
        self.pushButton.setIcon(self.icon)
        self.pushButton.clicked.connect(self.startTime)
程序重置
def Reset(self):
        self.TimeEnd()
        self.pushButton.setIcon(self.icon)
        self.pushButton.setEnabled(False)
        setNum[0] = 0
        setNum[1] = 0
        setNum[2] = 0
        self.lcdNumber.setProperty("intValue", setNum[0])
        self.lcdNumber_2.setProperty("intValue", setNum[1])
        self.lcdNumber_3.setProperty("intValue", setNum[2])
        for i in range(len(js)):
            js[i] = 1

def TimeEnd(self):
        color[0] = 0
        if self.timer_id == 0:
            pass
        else:
            self.killTimer(self.timer_id)
            timer_id = 0
            tj[0] = 0
程序颜色设置
def Color(self, color_a):
        self.label.setStyleSheet("color: {};".format(color_a))
        self.label_2.setStyleSheet("color: {};".format(color_a))
        self.lcdNumber.setStyleSheet("color: {};".format(color_a))
        self.lcdNumber_2.setStyleSheet("color: {};".format(color_a))
        self.lcdNumber_3.setStyleSheet("color: {};".format(color_a))

#每个色块都是一个函数

    def color_1(self):
        color[0] = 1
        self.Color("rgb(170, 0, 0)")


    def color_2(self):
        color[0] = 2
        self.Color("rgb(0, 255, 0)")


    def color_3(self):
        color[0] = 3
        self.Color("rgb(255, 0, 0)")


    def color_4(self):
        color[0] = 4
        self.Color("rgb(0, 0, 127)")
时间窗体设计
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(384, 92)
        Form.setMaximumSize(QtCore.QSize(384, 92))
        Form.setCursor(QtGui.QCursor(QtCore.Qt.BusyCursor))
        #Form.move(1530, 0)
        self.lcdNumber = MyLCDNumber(Form)
        self.lcdNumber.setGeometry(QtCore.QRect(0, 0, 101, 91))
        self.lcdNumber.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.lcdNumber.setFrameShadow(QtWidgets.QFrame.Raised)
        self.lcdNumber.setSmallDecimalPoint(False)
        self.lcdNumber.setDigitCount(2)
        self.lcdNumber.setMode(QtWidgets.QLCDNumber.Dec)
        self.lcdNumber.setProperty("value", 0.0)
        self.lcdNumber.setProperty("intValue", 0)
        self.lcdNumber.setObjectName("lcdNumber")
        self.lcdNumber_2 = MyLCDNumber_2(Form)
        self.lcdNumber_2.setGeometry(QtCore.QRect(120, 0, 101, 91))
        self.lcdNumber_2.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.lcdNumber_2.setSmallDecimalPoint(False)
        self.lcdNumber_2.setDigitCount(2)
        self.lcdNumber_2.setMode(QtWidgets.QLCDNumber.Dec)
        self.lcdNumber_2.setProperty("value", 0.0)
        self.lcdNumber_2.setProperty("intValue", 0)
        self.lcdNumber_2.setObjectName("lcdNumber_2")
        self.lcdNumber_3 = MyLCDNumber_3(Form)
        self.lcdNumber_3.setGeometry(QtCore.QRect(240, 0, 101, 91))
        self.lcdNumber_3.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.lcdNumber_3.setSmallDecimalPoint(False)
        self.lcdNumber_3.setDigitCount(2)
        self.lcdNumber_3.setMode(QtWidgets.QLCDNumber.Dec)
        self.lcdNumber_3.setProperty("value", 0.0)
        self.lcdNumber_3.setProperty("intValue", 0)
        self.lcdNumber_3.setObjectName("lcdNumber_3")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(100, -10, 21, 111))
        font = QtGui.QFont()
        font.setPointSize(40)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(220, -10, 21, 111))
        font = QtGui.QFont()
        font.setPointSize(40)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.pushButton = MypushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(350, 0, 31, 31))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
        
        self.pushButton.setSizePolicy(sizePolicy)
        self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton.setInputMethodHints(QtCore.Qt.ImhNone)
        self.pushButton.setText("")
        self.icon = QtGui.QIcon()
        self.icon.addPixmap(QtGui.QPixmap("./1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.icon_2 = QtGui.QIcon()
        self.icon_2.addPixmap(QtGui.QPixmap("./2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton.setIcon(self.icon)
        self.pushButton.setCheckable(False)
        self.pushButton.setObjectName("pushButton")
        
        self.pushButton_2 = MypushButton_2(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(350, 30, 31, 31))
        self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
        self.pushButton_2.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("./4.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_2.setIcon(icon1)
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_3 = MypushButton_3(Form)
        self.pushButton_3.setGeometry(QtCore.QRect(350, 60, 31, 31))
        self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_3.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("./3.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_3.setIcon(icon2)
        self.pushButton_3.setObjectName("pushButton_3")
        self.Color("green")
        
        
        #设置事件
        self.pushButton.clicked.connect(self.startTime)
        self.pushButton_3.clicked.connect(self.Mytimerstart)
        self.pushButton_2.clicked.connect(self.Reset)
        self.pushButton.setEnabled(False)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        self.Form = Form
        self.Form.move(int(move[0]), int(move[1]))

def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", ":"))
        self.label_2.setText(_translate("Form", ":"))
计时部分(判断当前处于什么状态:时钟、倒计时、正计时、开启提示、关闭程序)
if int(tj[0]) == 1:
            if int(js[3]) == 1:
                now_time = int(time.time())
                self.jg = now_time - self.start_time
                if int(js[0]) == 1:
                    #print(js[0])
                    if self.jg == 0:
                        pass
                    else:
                        if self.jg == self.a:
                            pass
                        else:
                            if int(setNum[2]) == 0:
                                if int(setNum[1]) == 0:
                                    if int(setNum[0]) == 0:
                                        self.Stop()
                                        self.pushButton.setEnabled(False)
                                        if int(js[1]) == 1:
                                            dlog = MyQDialog_Notime()
                                            dlog.exec_()
                                        if int(js[2]) == 0:
                                            self.close()
                                    else:
                                        setNum[0] = int(setNum[0]) - 1
                                        setNum[1] = 59
                                        setNum[2] = 60
                                        self.djs()
                                        self.setNum()
                                else:
                                    setNum[1] = int(setNum[1]) - 1
                                    setNum[2] = 60
                                    self.djs()
                                    self.setNum()
                            else:
                                self.djs()
                                self.setNum()
                else:
                    #print(setNum)
                    if self.jg == 0:
                        pass
                    else:
                        if self.jg == self.a:
                            pass
                        else:
                            if int(setNum[2]) >= 59:
                                if int(setNum[1]) >= 59:
                                    if int(setNum[0]) >= 99:
                                        self.TimeEnd()
                                        self.pushButton.setIcon(self.icon)
                                        self.pushButton.clicked.disconnect(self.Stop)
                                        self.pushButton.setEnabled(False)
                                        if int(js[1]) == 1:
                                            dlog = MyQDialog_Notime()
                                            dlog.label.setText("爆表了")
                                            dlog.exec_()
                                        if int(js[2]) == 0:
                                            self.close()
                                        self.pushButton.clicked.connect(self.startTime)                                
                                    else:
                                        if setNum[0] < int(self.maxhour):
                                            setNum[0] = int(setNum[0]) + 1
                                            setNum[1] = 0
                                            self.setNum()
                                        else:
                                            self.TimeEnd()
                                            self.pushButton.setIcon(self.icon)
                                            self.pushButton.clicked.disconnect(self.Stop)
                                            self.pushButton.setEnabled(False)
                                            if int(js[1]) == 1:
                                                dlog = MyQDialog_Notime()
                                                dlog.label.setText("爆表了")
                                                dlog.exec_()
                                            if int(js[2]) == 0:
                                                self.close()
                                            self.pushButton.clicked.connect(self.startTime)                
                                else:
                                    if setNum[1] < int(self.maxmin):
                                        setNum[1] = int(setNum[1]) + 1
                                        setNum[2] = 0
                                        self.setNum()
                                    else:
                                        setNum[1] = int(setNum[1]) + 1
                                        setNum[2] = 0
                                        self.setNum()
                                        self.TimeEnd()
                                        self.pushButton.setIcon(self.icon)
                                        self.pushButton.clicked.disconnect(self.Stop)
                                        self.pushButton.setEnabled(False)
                                        if int(js[1]) == 1:
                                            dlog = MyQDialog_Notime()
                                            dlog.label.setText("爆表了")
                                            dlog.exec_()
                                        if int(js[2]) == 0:
                                            self.close()
                                        self.pushButton.clicked.connect(self.startTime)
                            else:
                                setNum[2] = int(setNum[2]) + 1
                                self.a = self.jg
                                self.setNum()
            else:
                now_time = time.localtime()
                self.lcdNumber.setProperty("intValue", int(now_time.tm_hour))
                self.lcdNumber_2.setProperty("intValue", int(now_time.tm_min))
                self.lcdNumber_3.setProperty("intValue", int(now_time.tm_sec))
        else:
            pass
设置窗体初始化(设置时间边界,读取各项选项初始值)
def Mytimerstart(self):
        self.Reset()
        self.timer_id = self.startTimer(20)
        dlog = MyQDialog()
        dlog.exec_()
        self.TimeEnd()
        if js[4] == 0:
            self.close()
        if int(js[3]) == 1:
            if int(setNum[0]) + int(setNum[1]) + int(setNum[2]) == 0:
                if int(js[0]) == 0:
                    setNum[0] = 99
                    setNum[1] = 60
                    setNum[2] = 60
                    self.pushButton.setEnabled(True)
                    if int(setNum[0]) > 0:
                        self.maxhour = int(setNum[0]) - 1
                        setNum[0] = int(setNum[0]) - 1
                        self.maxmin = 60
                        setNum[1] = 60
                        setNum[0] = 0
                        setNum[1] = 0
                        setNum[2] = 0
                    else:
                        self.maxmin = int(setNum[1]) - 1
                        setNum[1] = int(setNum[1]) - 1
                        self.maxsec = setNum[2]
                        setNum[0] = 0
                        setNum[1] = 0
                        setNum[2] = 0
                else:
                    pass
            else:
                self.pushButton.setEnabled(True)
                if int(js[0]) == 1:
                    self.setNum()
                else:
                    if int(setNum[0]) > 0:
                        self.maxhour = int(setNum[0]) - 1
                        setNum[0] = int(setNum[0]) - 1
                        self.maxmin = 60
                        setNum[1] = 60
                        setNum[0] = 0
                        setNum[1] = 0
                        setNum[2] = 0
                    else:
                        self.maxmin = int(setNum[1]) - 1
                        setNum[1] = int(setNum[1]) - 1
                        self.maxsec = setNum[2]
                        setNum[0] = 0
                        setNum[1] = 0
                        setNum[2] = 0
        else:
            tj[0] = 1
            self.timer_id = self.startTimer(500)

你可能感兴趣的:(Python,python)