吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6101|回复: 7
收起左侧

[Python 转载] 简易电脑版小闹钟自给自足

  [复制链接]
zhan170 发表于 2019-5-11 14:45
这个简易工具是在我手机坏掉的情况,用电脑来当闹钟(高成本),请勿随意使用!!!

[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 微信截图_20190511144353.png

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
hjx8003 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

bydlyzx 发表于 2019-5-11 14:57
这是 Python2 写的 还是 Python3 啊?

在最新版的 PyCharm 里,怎么无法运行,提示:

SyntaxError: invalid character in identifier
zjk414 发表于 2019-5-11 15:13
luxiaole 发表于 2019-5-11 15:15
firework168 发表于 2019-5-11 15:34
很羡慕你们会写小程序的人
ggggzi 发表于 2019-5-11 16:46
会写程序的大神 真好
slofLeo 发表于 2019-5-11 21:44
看着像python3的
fish.1437 发表于 2019-5-13 14:55
感谢大神分享,谢谢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-16 08:53

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表