筆記本電腦關機快捷鍵

無論家用電腦還是公司的電腦,定時開關機都是一個非常實用的功能,只是一般都不太受關注 。定時關機不僅能延長電

腦的使用壽命,還能節約超多的電費呢~哈哈哈哈
筆記本電腦關機快捷鍵

??
嗨~這不,周天休假一天 , 但是公司的電腦大部分的小伙伴兒就開了一天,有時候放長假的時候電腦一開就是幾天 。
這不?隔壁的小姐姐已經被領導發現了,最后的最后這個事情就落到我手里了,開發一個能定時關
機的源碼項目供大家使用,并互相提醒每個人一定要下班關機!
定時開關機是個非常簡單又實用的功能,跟著本文用不了10分鐘你就能學會如何進行操作了哈~
???
筆記本電腦關機快捷鍵

?
筆記本電腦關機快捷鍵

??

正文

本文介紹了:普通人關機的習慣方式、以及程序員關機的方式哈!
并且程序員關機附了2份代碼喜歡tkinter的就用tk版本的,喜歡pyqt5的就用這版本的 。兩個版本大
家自己愛用那個用那個哈~

一、普通人關機

0)優雅的關機


筆記本電腦關機快捷鍵

?

1)快捷鍵關機

使用快捷鍵關機相信是大家比較常用的方法了吧?也是最簡單方便的方法 。
按下快捷鍵【Alt】+【F4】彈出功能對話框,實現快速關機,又快又準效率極高 。
筆記本電腦關機快捷鍵

?

2)任務管理器關機

這個方法和上一個快捷鍵關機的方法有著異曲同工之妙,按下快捷鍵【Alt】+【Ctrl】+
【Delete】 , 打開任務管理器 , 右下方有個圓形關機按鈕,點擊即可關機 。
筆記本電腦關機快捷鍵

?

3)設置關機時間

這個方法可以實現定時關機 , 算好想要關機的時間,設置完成后電腦到點就會自動關機 。再也不用
因為電腦關機更新而等個半天了 。按下快捷鍵【win】+【R】,在運行對話框內輸入《at20:00
shutdown-s》后點擊確定,系統就會在晚上8點準時關機 。這個方法可以在大家確定能夠關機時間
的情況下使用還是非常方便的 。
筆記本電腦關機快捷鍵

?

4)鼠標滑動關機

在電腦桌面位置創建一個快捷方式,在出現的對話框內輸入slidetoshutdown后點下一步 。
筆記本電腦關機快捷鍵

?
點擊完成即可 。
筆記本電腦關機快捷鍵

?
此時電腦桌面上就多了一個快捷方式,想要關機時雙擊該快捷方式 , 就會出現以下提示,滑動即可
已關閉電腦了 。
筆記本電腦關機快捷鍵

?

二、程序員關機

嘿嘿~雖然確實正常人開關機上面的更方便快速哈!但是源碼打包成exe點開更方便啦~尤其是在電
腦需要幾個小時之后關機的,需要先讓電腦自動完成任務再關機滴~那這個還蠻方便的~也許,應
該更方便.jpg 強行解釋的我2333~這就是娛樂娛樂的代碼哈哈哈哈~

1)Pyqt5界面化小程序

1.1 附源碼項目

-*—coding:utf-8 -*-import sysimport osPython執行系統命令方法所用到的包from PyQt5 import QtCore,QtGui,QtWidgetsclassUi_shut(object):類 繼承object類flag = TruedefsetupUi(self,shut):方法設置窗體的大小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))標簽的位置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)為pushButton添加監聽事件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是一個QMetaObject類里的靜態函數,其作用是用來將QObject * o里的子QObject的某些信號按照其objectName連接到o的槽上 。defretranslateUi(self,shut):_translate = QtCore.QCoreApplication.translateshut.setWindowTitle(_translate("shut","Windows定時關機器"))self.label.setText(_translate("shut","在:"))self.label_2.setText(_translate("shut","時"))self.label_3.setText(_translate("shut","分"))self.label_4.setText(_translate("shut"," 請輸入關機時間"))self.pushButton.setText(_translate("shut","設置"))defsd(self,shut):self.sd為觸發該事件后 , 需要執行的操作 。h =self.lineEdit.text()m =self.lineEdit_2.text()ifself.flag:self.flag = Falsetry:捕獲所有異常os.popen(at+ h +:+ m +shutdown -s)python執行cmd命令的方法self.label_4.setText(設置成功! 系統將關機在今天+h+:+m)self.pushButton.setText(移除)self.lineEdit.clear()self.lineEdit_2.clear()except:self.label_4.setText(Something is wrong~)else:self.flag = Truetry:os.popen(at /delete /yes)self.label_4.setText(成功,全部移除)self.pushButton.setText(Set)self.lineEdit.clear()self.lineEdit_2.clear()except:self.label_4.setText(Something is wrong)

1.2 效果展示


筆記本電腦關機快捷鍵

?

?2)Tkinter界面化小程序

2.1 附源碼項目

from tkinter import ttkimport osimport tkinter.messagebox as message_boxwindows = tkinter.Tk()windows.title("Python定時關機")window 居中windows.update()update window ,must docurWidth =280get current widthcurHeight = windows.winfo_reqheight()get current heightscnWidth, scnHeight = windows.maxsize()get screen width and heightnow generate configuration informationconfig =%dx%d+%d+%d% (curWidth, curHeight,(scnWidth - curWidth) /2, (scnHeight - curHeight) /2)windows.geometry(config)root 容器root = ttk.LabelFrame(windows,text="關機命令")root.grid(column=0,row=0, padx=15, pady=15)提醒文本tkinter.Label(root,text="輸入時間").grid(column=0,row=0, sticky=tkinter.W)tkinter.Label(root,text="選擇").grid(column=1,row=0)存儲輸入的值time= tkinter.StringVar()unit = tkinter.StringVar()輸入框time_edit = tkinter.Entry(root, width=10, textvariable=time)time_edit.grid(column=0,row=1, padx=4, sticky=tkinter.W)time_edit.focus()下拉單位選擇unit_arr = (時,分,秒)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)defchange_edit(to_time):time_edit.delete(0,10)time_edit.insert(0, to_time)unit_chosen.current(1)startdefstart():iftime.get()andunit.get():message_box.showwarning("選擇完畢","你的電腦將在多少 %s %s"% (time.get(), unit.get()))shutdown 的秒數count_down_second =int(time.get())ifunit.get() ==hour:count_down_second *=3600elif unit.get() ==minute:count_down_second *=60executeos.system("shutdown -s -t %s"% count_down_second)windows.quit()canceldefcancel():os.system("shutdown -a")windows.quit()start 按鈕start_action = tkinter.Button(root,text="START", command=start)start_action.grid(column=2,row=1)文本tip_label = tkinter.Label(root,text="倒計時關機")tip_label.grid(row=2,column=0, pady=2)快捷選擇時間fram = tkinter.Frame(root)fram.grid(row=3,column=0, columnspan=3)常用的時間foriinrange(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 按鈕cancel_action = tkinter.Button(root,text="CANCEL", command=lambda:cancel())cancel_action.grid(row=4,column=1, pady=10, sticky=tkinter.W)

2.2 效果展示


筆記本電腦關機快捷鍵

?
?

總結

【筆記本電腦關機快捷鍵】好啦,定時關機的小項目就over了 。以后記得需要定時關機的就用這款代碼哈哈哈~想什么時候關機就什么時候關機嘛

相關經驗推薦