Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the computer shut down at the specified time by Python?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge about "Python how to make the computer shut down at the specified time". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

First look at the renderings

code is as follows

from tkinter import messagebox #messagepop import os #Used to execute cmd command import string #StringVar to use String Hook def text(): #Determine whether it is a number and process hours into seconds i=time.get() #Get string hook value try: wrong arrest Determine whether it is a number i=str(int(float(i)*60*60)) except ValueError: messagebox.showwarning(title="Input error",message="Please enter a number! ") #Warning message pop-up else: result=shutdown(i) def shutdown(i=False): #Execute cmd statement to set timed shutdown if i==False: result=os.system("shutdown -a") if result: messagebox.showwarning(title="Error",message="Currently no timing shutdown task") return 0 else: result=os.system("shutdown -s -t "+i) if result: result=os.system("shutdown -a") if not result: result=os.system("shutdown -s -t "+i) if not result: messagebox.showinfo(title="Status message",message="Success! ") else: messagebox.showerror(title="Error",message="Failure for unknown reason") soft=Tk()soft.title=()soft.geometry('155x90+885+465') #Initialize window size information soft.resizable(0, 0) #Setting window size cannot be changed text1=Label(soft,text="How many hours do you need to shut down? ",compound="center").grid(row=0,column=0,columnspan=2,padx=0,pady=0) #text time=StringVar() #declaration string hook time.set("1") #Set initial values text2=Entry(soft,textvariable=time).grid(row=1,column=0,columnspan=2,padx=5,pady=0) #Set Text Box grid button1=Button(soft,text="Cancel Task",command=shutdown).grid(row=2,column=0,padx=5,pady=10)button2=Button(soft,text="Set Task",command=text).grid(row=2,column=1,padx=5,pady=10)soft.mainloop() #Run

If you want to cancel, click Cancel Mission.

"Python how to achieve computer shutdown at the specified time" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report