定时关机(python)

内容

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

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

shutdown -s -t 60

代码

# -*- 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值