首页 编程教程正文

简易电脑版小闹钟自给自足

piaodoo 编程教程 2020-02-22 22:03:12 927 0 python教程

本文来源吾爱破解论坛

这个简易工具是在我手机坏掉的情况,用电脑来当闹钟(高成本),请勿随意使用!!!

[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_())


微信截图_20190511143804.png (24 KB, 下载次数: 2)

下载附件  保存到相册

2019-5-11 14:40 上传

微信截图_20190511144353.png (3.53 KB, 下载次数: 3)

下载附件  保存到相册

2019-5-11 14:44 上传

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/7438.html

搜索