定时关机(python)

内容

为了更简单地实现定时关机,不必去记繁琐的命令行,于是搞了一个gui出来

基于python和Windows命令行实现,核心为:

bash 复制代码
shutdown -s -t 60

代码

python 复制代码
# -*- coding: utf-8 -*-
# Environment    PyCharm
# File_name   autoShutdownPro |User    Pfolg
# 2024/10/09 12:44
import os
import tkinter as tk


# print("程序开始运行时会取消已设置的定时关机")
#
# try:
#     time = int(input('计划在多少分钟后关机(整数) 或者 回车取消定时关机:'))
#     basic_time = time * 60
#     text = f'shutdown -s -t {basic_time}'
#     os.system(text)
#     input(f"已设置,您的系统将于{basic_time}秒后关闭\n回车开始:")
# except ValueError:
#     input("回车退出:")
def autoShutdown(time):
    if time:
        os.system(f"shutdown -s -t {time}")


if __name__ == '__main__':
    os.system("shutdown -a")
    # 窗口设置
    window = tk.Tk()
    w, h = window.winfo_screenwidth(), window.winfo_screenheight()
    window.geometry(f"{int(w / 4)}x{int(h / 4)}+{int(w / 4)}+{int(h / 4)}")
    window.title("Auto_Shutdown_Pro")
    # 标签
    tk.Label(window, text="Time Setting", font=("微软雅黑 bold", 16)).place(relx=.02, rely=.02)

    # 控件设置
    day, hour, minute, second = tk.IntVar(), tk.IntVar(), tk.IntVar(), tk.IntVar()
    # day
    tk.Entry(window, width=8, textvariable=day).place(relx=.25, rely=.25)
    tk.Label(window, text="Day:").place(relx=.1, rely=.25)
    # hour
    tk.Entry(window, width=8, textvariable=hour).place(relx=.25, rely=.4)
    tk.Label(window, text="Hour:").place(relx=.1, rely=.4)
    # minute
    tk.Entry(window, width=8, textvariable=minute).place(relx=.25, rely=.55)
    tk.Label(window, text="Min:").place(relx=.1, rely=.55)
    # second
    tk.Entry(window, width=8, textvariable=second).place(relx=.25, rely=.7)
    tk.Label(window, text="Second:").place(relx=.1, rely=.7)

    # 标签及按钮
    tk.Label(window, text="shutdown -a\nshutdown -s -t 60\nIt will run \ncommand one at first.").place(relx=.6, rely=.3)
    tk.Button(
        window, text="Set", width=8, command=lambda: autoShutdown(
            (
                    (
                            int(day.get()) * 24 + int(hour.get())
                    ) * 60 + int(minute.get())
            ) * 60 + int(second.get())
        )
    ).place(relx=.55, rely=.7)
    tk.Button(window, text="Cancel", width=8, command=lambda: os.system("shutdown -a")).place(relx=.75,rely=.7)

    window.mainloop()

实现效果

其实我主要是为了学习剪视频,虽然两个都比较烂......

定时关机程序

如何获取

单一程序及源码:

Release AutoShutdownPro · Pfolg/Pfolg_Source (github.com)

集成工具箱:

Pfolg/PGBox: 平时写的小程序的大杂烩------整合后的工具箱,主要功能基于windows系统实现 (github.com)

相关推荐
Y学院14 小时前
Python 数据分析:从新手到高手的“摸鱼”指南
python·数据分析
深耕AI14 小时前
【PyTorch训练】准确率计算(代码片段拆解)
人工智能·pytorch·python
eqwaak015 小时前
科技信息差(9.12)
开发语言·python·科技·量子计算
Blossom.11815 小时前
从“能写”到“能干活”:大模型工具调用(Function-Calling)的工程化落地指南
数据库·人工智能·python·深度学习·机器学习·计算机视觉·oracle
蒋星熠15 小时前
破壁者指南:内网穿透技术的深度解构与实战方法
网络·数据库·redis·python·websocket·网络协议·udp
shizidushu15 小时前
使用 Pyinstaller 打包 PPOCRLabel
python·pyinstaller
Q_Q196328847516 小时前
python+springboot+uniapp微信小程序题库系统 在线答题 题目分类 错题本管理 学习记录查询系统
spring boot·python·django·uni-app·node.js·php
Rhys..16 小时前
.gitignore文件的作用及用法
python·github
IT学长编程17 小时前
计算机毕业设计 基于深度学习的酒店评论文本情感分析研究 Python毕业设计项目 Hadoop毕业设计选题 机器学习选题【附源码+文档报告+安装调试】
hadoop·python·深度学习·机器学习·数据分析·毕业设计·酒店评论文本情感分析