[Python] 纯文本查看 复制代码
#界面包
from PyQt5 import QtCore, QtWidgets
#系统包
from sys import argv, exit
#系统命令包
from os import system
#时间操作包
from datetime import datetime,timedelta
class Ui_MainWindow(object):
def __init__(self):
self.codeall=0
self.codeok=0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(365,265)
MainWindow.setFixedSize(365,265)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(270, 160, 75, 30))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(10, 160, 250, 30))
self.lineEdit.setObjectName("lineEdit")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(10, 10, 345, 100))
self.textEdit.setObjectName("textEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 200, 120, 30))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 200, 80, 30))
self.label.setObjectName("label")
self.label_codeall = QtWidgets.QLabel(self.centralwidget)
self.label_codeall.setGeometry(QtCore.QRect(10, 120, 35, 30))
self.label_codeall.setObjectName("label_codeall")
self.label_codeall_child = QtWidgets.QLabel(self.centralwidget)
self.label_codeall_child.setGeometry(QtCore.QRect(47, 120, 130, 30))
self.label_codeall_child.setObjectName("label_codeall_child")
self.label_codeok = QtWidgets.QLabel(self.centralwidget)
self.label_codeok.setGeometry(QtCore.QRect(175, 120, 35, 30))
self.label_codeok.setObjectName("label_codeok")
self.label_codeok_child = QtWidgets.QLabel(self.centralwidget)
self.label_codeok_child.setGeometry(QtCore.QRect(212, 120, 130, 30))
self.label_codeok_child.setObjectName("label_codeok_child")
# 左边距, 上边距 ,宽,高
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 365, 30))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "小闹钟"))
self.pushButton.setText(_translate("MainWindow", "开启"))
tomorrow=(datetime.now()+timedelta(days=1)).strftime("%Y-%m-%d")
self.lineEdit_2.setText(_translate("MainWindow", tomorrow+" 07:40"))
self.label.setText(_translate("MainWindow", "起床时间"))
self.label_codeall.setText(_translate("MainWindow", "请求数"))
self.label_codeall_child.setText(_translate("MainWindow", "0"))
self.label_codeok.setText(_translate("MainWindow", "处理数"))
self.label_codeok_child.setText(_translate("MainWindow", "0"))
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.audio_go)
self.pushButton.setCheckable(True)
self.pushButton.clicked.connect(self.audio_go)
def audio_go(self):
on_off=self.pushButton.isChecked()
if on_off==True :
self.timer.start(10000)
now_hm=datetime.now().strftime("%Y-%m-%d %H:%M")
self.lineEdit.setText("当前时间"+now_hm)
wakeup=self.lineEdit_2.text()
self.codeall+=1
self.label_codeall_child.setText(str(self.codeall))
if now_hm>=wakeup :
self.codeok+=1
self.label_codeok_child.setText(str(self.codeok))
system('Unity-TheFatRat.mp3')
self.pushButton.setCheckable(False)
self.pushButton.setText("停止")
else :
self.timer.stop()
self.pushButton.setText("开启")
if __name__ =='__main__':
app = QtWidgets.QApplication(argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
exit(app.exec_())