python-定时关机程序


import os,time,msvcrt
def shutdown():
 cancell()
 print("                                                                          ")
 print("")
 print("")
 print("                            ***********************************************")
 print("                                      如果有系统提示,请忽略=_=            ")
 print("                                 每次重新设定时间都会自动地取消自动关系                                        ")
 print("                             输入格式为  22:40:00  一定要用英文输入法输入  ")
#获取当前年月日 now
= time.strftime("%Y-%m-%d",time.localtime(time.time()))
#输入的时间加上年月日,这样只用输入时分秒即可 input_time
=now+" "+ str(input(" 请输入关机时间:")) print(" 输入回车键返回选择菜单")
#转化时间戳 time1
= time.strptime(input_time,"%Y-%m-%d %H:%M:%S") time2 = int(time.mktime(time1)) now = int(time.time()) #隔天关机的功能 if time2<now: time2=time2+86400
#计算时间 d=time2-now os.system('shutdown -s -t %d' %d) def cancel():#取消自动关机 os.system('shutdown -a') print("") print("") print(" ") print(" 输入回车键返回选择菜单") def main(): while True: os.system("cls") print("") print("") print(" 该程序只支持24小时内的自动关机 ") print("") print(" ***********************") print(" * 1、我要设定关机时间*") print(" * 2、我要取消自动关机*") print(" ***********************") print(" powered by 你说你妈呢") print(" 本人菜鸡,多多包容 ")
#从键盘上获取输入 ch
=msvcrt.getch() str1=bytes.decode(ch) os.system("cls") if str1=='1': shutdown() if str1=='2': cancel() print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") os.system("pause") main()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM