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