Hello! Hello, I'm Mengya.
Whether home computers or company computers, timing on-off is a very practical function, but it is generally not paid much attention. Timed shutdown can not only prolong power consumption
The service life of the brain can save too much electricity ~ ha ha ha
Hi ~ no, I take a day off on Sundays, but most of the company's computers are on for a day. Sometimes when I have a long holiday, the computer is on for a few days.
see? The little sister next door has been discovered by the leader, and the last thing falls into my hands. Develop one that can close regularly
Machine source code project for everyone to use, and remind each other that everyone must shut down after work!
Timing switch is a very simple and practical function. You can learn how to operate it in less than 10 minutes~
This article introduces: ordinary people's habit of shutting down, and programmers' way of shutting down, ha!
And the programmer shut down and attached two copies of code. If you like tkinter, use tk version, and if you like pyqt5, use this version. Two versions are large
I love to use that at home~
1, Ordinary people shut down
0) graceful shutdown
1) Shortcut key shutdown
Use the shortcut key to shut down, I believe it is a more commonly used method? It is also the simplest and most convenient method.
Press the shortcut key [Alt] + [F4] to pop up the function dialog box to realize fast and accurate shutdown, with high efficiency.
2) Task manager shutdown
This method is similar to the previous shortcut key shutdown method. Press the shortcut key [Alt] + [Ctrl] +
[Delete] open the task manager. There is a circular shutdown button at the lower right. Click it to shut down.
3) Set shutdown time
This method can realize regular shutdown, calculate the time you want to shut down, and the computer will shut down automatically at point after setting. Never again
I've been waiting for a long time because the computer is turned off and updated. Press the shortcut key [win] + [R], and enter "at20:00" in the operation dialog box
Click OK after "shutdown-s" and the system will shut down on time at 8 p.m. This method can be used to determine the shutdown time
It is very convenient to use in the case of.
4) Mouse sliding shutdown
Create a shortcut on the computer desktop, enter "slide to shutdown" in the dialog box that appears, and then click next.
At this time, there is a shortcut on the computer desktop. When you want to shut down, double-click the shortcut, and the following prompt will appear. Just slide
The computer has been turned off.
2, Programmer shutdown
Although it is true that normal people can switch on and off the machine more conveniently and quickly, ha! But it's more convenient to package the source code into exe, especially when the computer needs to be shut down after a few hours. It's quite convenient to let the computer automatically complete the task before shutting down. Maybe it should be more convenient. jpg forcibly explained me 2333. This is the code of entertainment. Hahaha. Finally, if you don't have a lot of time and want to improve python quickly, The most important thing is that you are not afraid of hardship. I suggest you can the price (homonym): 762459510. That's really good. Many people make rapid progress. You need to be not afraid of hardship! You can add it and have a look~
1) Pyqt5 interface applet
1.1 project with source code
# -*—coding:utf-8 -*-import sysimport os # Packages used by Python to execute system command methods from pyqt5 import qtcore, qtgui, qtwidgets class UI_ shut(object): #Class inherits the object class flag = True def setupUi(self,shut): #method #Sets the size of the form shut.setObjectName("shut") shut.resize(420,180) shut.setFixedSize(420,180) self.label = QtWidgets.QLabel(shut) self.label.setGeometry(QtCore.QRect(40,50,41,51)) #Label location self.label.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.label.setObjectName("label") self.lineEdit = QtWidgets.QLineEdit(shut) self.lineEdit.setGeometry(QtCore.QRect(70, 50, 71, 41)) self.lineEdit.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.lineEdit.setObjectName("lineEdit") self.label_2 = QtWidgets.QLabel(shut) self.label_2.setGeometry(QtCore.QRect(150, 60, 31, 31)) self.label_2.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.label_2.setObjectName("label_2") self.lineEdit_2 = QtWidgets.QLineEdit(shut) self.lineEdit_2.setGeometry(QtCore.QRect(180, 50, 71, 41)) self.lineEdit_2.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.lineEdit_2.setObjectName("lineEdit_2") self.label_3 = QtWidgets.QLabel(shut) self.label_3.setGeometry(QtCore.QRect(260, 60, 31, 31)) self.label_3.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.label_3.setObjectName("label_3") self.pushButton = QtWidgets.QPushButton(shut,clicked=self.sd) #by pushButton Add listening event click. self.pushButton.setGeometry(QtCore.QRect(290, 50, 101, 41)) self.pushButton.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.pushButton.setObjectName("pushButton") self.label_4 = QtWidgets.QLabel(shut) self.label_4.setGeometry(QtCore.QRect(0, 120, 500, 31)) self.label_4.setFont(QtGui.QFont("Roman times",10,QtGui.QFont.Bold)) self.label_4.setObjectName("label_4") self.retranslateUi(shut) QtCore.QMetaObject.connectSlotsByName(shut) #connectSlotsByName is a static function in the QMetaObject class. It is used to connect some signals of the child QObject in QObject * o to the slot of O according to its objectName. def retranslateUi(self,shut): _translate = QtCore.QCoreApplication.translate shut.setWindowTitle(_translate("shut", "Windows Turn off the machine regularly")) self.label.setText(_translate("shut", "At:")) self.label_2.setText(_translate("shut", "Time")) self.label_3.setText(_translate("shut", "branch")) self.label_4.setText(_translate("shut", " Please enter the shutdown time")) self.pushButton.setText(_translate("shut", "set up")) def sd(self,shut): #self.sd is the action to be performed after the event is triggered. h = self.lineEdit.text() m = self.lineEdit_2.text() if self.flag: self.flag = False try: #Catch all exceptions os.popen('at'+ h + ':' + m + ' shutdown -s') #How python executes cmd command self.label_4.setText(' Set successfully! The system will shut down today '+h+':'+m) self.pushButton.setText('remove') self.lineEdit.clear() self.lineEdit_2.clear() except: self.label_4.setText('Something is wrong~') else: self.flag = True try: os.popen('at /delete /yes') self.label_4.setText('Successfully, remove all') self.pushButton.setText('Set') self.lineEdit.clear() self.lineEdit_2.clear() except: self.label_4.setText('Something is wrong')
1.2 effect display
2) Tkinter interface applet
2.1 project with source code
from tkinter import ttkimport osimport tkinter.messagebox as message_boxwindows = tkinter.Tk()windows.title("Python Timed shutdown")# window Center windows.update() # update window ,must docurWidth = 280 # get current widthcurHeight = windows.winfo_reqheight() # get current heightscnWidth, scnHeight = windows.maxsize() # get screen width and height# now generate configuration informationconfig = '%dx%d+%d+%d' % (curWidth, curHeight, (scnWidth - curWidth) / 2, (scnHeight - curHeight) / 2)windows.geometry(config)# root container root = ttk.LabelFrame(windows, text="Shutdown command")root.grid(column=0, row=0, padx=15, pady=15)# Reminder text tkinter.Label(root, text="Input time").grid(column=0, row=0, sticky=tkinter.W)tkinter.Label(root, text="choice").grid(column=1, row=0)# Store the entered value time = tkinter.StringVar()unit = tkinter.StringVar()# Input box time_edit = tkinter.Entry(root, width=10, textvariable=time)time_edit.grid(column=0, row=1, padx=4, sticky=tkinter.W)time_edit.focus()# Drop down unit selection unit_arr = ('Time', 'branch', 'second')unit_chosen = ttk.Combobox(root, width=6, textvariable=unit, state='readonly')unit_chosen['values'] = unit_arrunit_chosen.grid(column=1, row=1)unit_chosen.current(0)def change_edit(to_time): time_edit.delete(0, 10) time_edit.insert(0, to_time) unit_chosen.current(1)# startdef start(): if time.get() and unit.get(): message_box.showwarning("Selection complete", "How much will your computer be %s %s" % (time.get(), unit.get())) # shutdown Number of seconds count_down_second = int(time.get()) if unit.get() == 'hour': count_down_second *= 3600 elif unit.get() == 'minute': count_down_second *= 60 # execute os.system("shutdown -s -t %s" % count_down_second) windows.quit()# canceldef cancel(): os.system("shutdown -a") windows.quit()# start Button start_action = tkinter.Button(root, text="START", command=start)start_action.grid(column=2, row=1)# text tip_label = tkinter.Label(root, text="Countdown shutdown")tip_label.grid(row=2, column=0, pady=2)# Quick select time fram = tkinter.Frame(root)fram.grid(row=3, column=0, columnspan=3)# Common time for i in range(2, 7): button = tkinter.Button(fram, text=str(i * 15) + "min", command=lambda x=i: change_edit(str(x * 15))) button.grid(row=0, column=i - 2, padx=2, pady=2, sticky=tkinter.W)# Cancel button cancel_action = tkinter.Button(root, text="CANCEL", command=lambda: cancel())cancel_action.grid(row=4, column=1, pady=10, sticky=tkinter.W)
2.2 effect display
Well, the small project of regular shutdown is over. Remember to use this code if you need to shut down regularly in the future. Hahaha ~ shut down whenever you want
⛳ Complete free source code collection:
For a complete project source code + material source code base, see: # private letter Xiaobian 06# you can get free benefits!
Your support is my biggest motivation!! Remember three times in a row, oh ~mua welcome to read previous articles~