开发背景:不知道大家有没有遇到这样的情况,在公司总有那么一两台电脑,是需要共享使用的,但是共享的电脑使用人如果要提前下班,最好的方式就是使用定时关机,系统自带的命令确实能够实现,但命令参数不是所有人能操控的了,网上的定时器也试用了好几个,要么是某软件附带的功能,要么是附带其他很多不用的功能,想找一款简单纯粹的定时软件,好像也成了难事,如是乎,我自己动手,写出一个功能单一的定时关机器,为了自己方便的同时,也分享给大家一起来方便。 软件特色: 最大的特色就是:带有关机倒计时,并且大屏显示,而不是定时后自己都不知道 软件界面: ![]() ![]()
以上就是最实用的功能的完美定时器,吾爱破解论坛首发,非常的好用,不管你们用不用,反正我每天在用 import sys import datetime from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QRadioButton, QDateTimeEdit, QTimeEdit, QMessageBox) from PyQt6.QtCore import Qt, QTimer, QDateTime from PyQt6.QtGui import QFont, QPalette, QColor import subprocess class ShutdownTimer(QMainWindow): def __init__(self): super().__init__() self.shutdown_time = None self.timer = QTimer() self.timer.timeout.connect(self.update_countdown) self.init_ui() def init_ui(self): # 设置窗口 self.setWindowTitle('定时关机器V1.0 吾爱破解@mryouan') screen = QApplication.primaryScreen().geometry() self.setGeometry(screen.width()//4, screen.height()//4, screen.width()//2, screen.height()//2) # 主布局 central_widget = QWidget() self.setCentralWidget(central_widget) layout = QVBoxLayout(central_widget) # 倒计时显示区域 self.countdown_label = QLabel('未设置定时关机') self.countdown_label.setAlignment(Qt.AlignmentFlag.AlignCenter) self.countdown_label.setStyleSheet(""" QLabel { background-color: black; color: red; padding: 20px; border: 2px solid gray; border-radius: 10px; } """) self.countdown_label.setFont(QFont('Arial', 40)) layout.addWidget(self.countdown_label) # 设置区域 settings_widget = QWidget() settings_layout = QHBoxLayout(settings_widget) # 时间设置部分 time_widget = QWidget() time_layout = QVBoxLayout(time_widget) # 单选按钮 self.absolute_radio = QRadioButton('绝对时间') self.relative_radio = QRadioButton('相对时间') self.absolute_radio.setChecked(True) time_layout.addWidget(self.absolute_radio) time_layout.addWidget(self.relative_radio) # 时间选择器 self.datetime_edit = QDateTimeEdit() self.datetime_edit.setDateTime( QDateTime.currentDateTime().addSecs(3600)) # 默认一小时后 self.time_edit = QTimeEdit() self.time_edit.setTime(self.time_edit.time().addSecs(3600)) time_layout.addWidget(self.datetime_edit) time_layout.addWidget(self.time_edit) self.time_edit.hide() # 默认隐藏相对时间 settings_layout.addWidget(time_widget) # 按钮区域 button_widget = QWidget() button_layout = QVBoxLayout(button_widget) self.execute_btn = QPushButton('执行') self.cancel_btn = QPushButton('取消') button_layout.addWidget(self.execute_btn) button_layout.addWidget(self.cancel_btn) settings_layout.addWidget(button_widget) layout.addWidget(settings_widget) # 信号连接 self.absolute_radio.toggled.connect(self.toggle_time_input) self.execute_btn.clicked.connect(self.execute_shutdown) self.cancel_btn.clicked.connect(self.cancel_shutdown) def toggle_time_input(self): if self.absolute_radio.isChecked(): self.datetime_edit.show() self.time_edit.hide() else: self.datetime_edit.hide() self.time_edit.show() def execute_shutdown(self): if self.absolute_radio.isChecked(): shutdown_time = self.datetime_edit.dateTime().toPyDateTime() if shutdown_time <= datetime.datetime.now(): QMessageBox.warning(self, '警告', '请选��未来的时间!') return else: current_time = datetime.datetime.now() time_delta = datetime.timedelta( hours=self.time_edit.time().hour(), minutes=self.time_edit.time().minute(), seconds=self.time_edit.time().second() ) shutdown_time = current_time + time_delta self.shutdown_time = shutdown_time seconds = int((shutdown_time - datetime.datetime.now()).total_seconds()) # 设置关机命令 subprocess.run(['shutdown', '/s', '/t', str(seconds)]) # 更新UI self.execute_btn.setEnabled(False) self.execute_btn.setText('执行中') self.execute_btn.setStyleSheet('background-color: #90EE90; color: gray;') # 启动倒计时 self.timer.start(1000) def cancel_shutdown(self): reply = QMessageBox.question(self, '确认', '是否要修改定时?', QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) if reply == QMessageBox.StandardButton.Yes: # 取消当前关机命令 subprocess.run(['shutdown', '/a']) self.reset_ui() else: subprocess.run(['shutdown', '/a']) self.close() def reset_ui(self): self.shutdown_time = None self.timer.stop() self.countdown_label.setText('未设置定时关机') self.execute_btn.setEnabled(True) self.execute_btn.setText('执行') self.execute_btn.setStyleSheet('') def update_countdown(self): if self.shutdown_time: remaining = self.shutdown_time - datetime.datetime.now() if remaining.total_seconds() <= 0: self.timer.stop() return hours = remaining.seconds // 3600 minutes = (remaining.seconds % 3600) // 60 seconds = remaining.seconds % 60 self.countdown_label.setText( f'距离关机还有{hours:02d}小时{minutes:02d}分{seconds:02d}秒') if __name__ == '__main__': app = QApplication(sys.argv) app.setStyle('Fusion') # 使用 Fusion 风格,接近 Windows 10 风格 window = ShutdownTimer() window.show() sys.exit(app.exec()) |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)