最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)windows自動(dòng)關(guān)機(jī)功能

 更新時(shí)間:2025年01月15日 10:19:02   作者:Nobita?Chen  
這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)windows自動(dòng)關(guān)機(jī)功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下

python <shut.py>

import ntplib
from datetime import datetime, timezone

import time
import os

import easygui

# net time
def get_network_time():
    time.sleep(3)
    """從網(wǎng)絡(luò)時(shí)間服務(wù)器獲取時(shí)間"""
    client = ntplib.NTPClient()
    response = client.request('pool.ntp.org')
    utc_time = datetime.utcfromtimestamp(response.tx_time)
    beijing_time = utc_time + timedelta(hours = 8)
    return beijing_time
    #return datetime.fromtimestamp(response.tx_time, timezone.utc)


local = datetime.now()
if local.hour >=0 and local.hour<7:
    print("當(dāng)前時(shí)間處于0點(diǎn)至9點(diǎn)之間")
    os.system('shutdown /a')
    os.system('shutdown /s /t 60')
    easygui.msgbox("現(xiàn)在是休息時(shí)間,電腦即將關(guān)機(jī),請(qǐng)你馬上睡覺(jué)??!", "提示")
    easygui.msgbox("電腦即將關(guān)機(jī)!", "提示")
else:
    easygui.msgbox("當(dāng)前時(shí)間不處于0點(diǎn)至7點(diǎn)之間=>local:[{}]".format(local.hour), "提示")
    os.system('shutdown /s /t 9000')

    # 下面的代碼已經(jīng)在關(guān)機(jī)后了~~~
    time.sleep(10)

    # 每隔3小時(shí),執(zhí)行關(guān)機(jī)
    while True:
        print("每隔3小時(shí),執(zhí)行關(guān)機(jī)")
        easygui.msgbox("電腦將在2.5小時(shí)后關(guān)閉,請(qǐng)注意休息~~", "提示")
        time.sleep(10800)
        os.system('shutdown /a')
        os.system('shutdown /s /t 60')

'''
try:
    
    # 獲取網(wǎng)絡(luò)時(shí)間
    current_time = get_network_time()

    # 提取小時(shí)數(shù)
    hour = current_time.hour
    

    # 判斷是否處于0點(diǎn)至7點(diǎn)之間
    if 0 <= hour < 7:
        print("當(dāng)前時(shí)間處于0點(diǎn)至7點(diǎn)之間")
        os.system('shutdown /a')
        os.system('shutdown /s /t 60')
        easygui.msgbox("現(xiàn)在是休息時(shí)間,電腦即將關(guān)機(jī),請(qǐng)你馬上睡覺(jué)??!", "提示")
        easygui.msgbox("電腦即將關(guān)機(jī)!", "提示")
    else:
        easygui.msgbox("當(dāng)前時(shí)間不處于0點(diǎn)至7點(diǎn)之間=>remote[{}]".format(hour), "提示")
        os.system('shutdown /s /t 9000')
   

except:
    print('網(wǎng)絡(luò)異常?。?)

'''

vbe文件

Set ws = WScript.createObject("WScript.Shell")
ws.run "D:/data\Python/cmd.bat",0

<cmd.bat>

@echo off
title 執(zhí)行Python腳本

c: & cd c:\Users\Administrator\AppData\Local\Programs\Python\Python37
python "D:\data\Python\shut.py" >>"D:\data\Python\%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%-%time:~6,2%.txt"
::pause

計(jì)劃任務(wù),批處理,避免沖突

@echo off
::由于shutdown不能執(zhí)行多次,所以先取消后,再次執(zhí)行!

???????shutdown /a
shutdown /s /t 30

方法補(bǔ)充

除了上文的方法,下面小編為大家整理了其他的Python實(shí)現(xiàn)Windows自動(dòng)關(guān)機(jī)的方法,希望對(duì)大家有所幫助

完整代碼

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'shut.ui'
#
# Created: Mon Mar 20 18:10:31 2017
#      by: PyQt5 UI code generator 5.2.1
#
# WARNING! All changes made in this file will be lost!
import sys
import os
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_shut(object):
    flag = True
    def setupUi(self, shut):
        shut.setObjectName("shut")
        shut.resize(411, 170)
        shut.setFixedSize(411,170)
        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)
        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, 411, 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)

    def retranslateUi(self, shut):
        _translate = QtCore.QCoreApplication.translate
        shut.setWindowTitle(_translate("shut", "Auto Shutdown by dearvee"))
        self.label.setText(_translate("shut", "At:"))
        self.label_2.setText(_translate("shut", "H"))
        self.label_3.setText(_translate("shut", "M"))
        self.label_4.setText(_translate("shut", "Please input time of shutdown~"))
        self.pushButton.setText(_translate("shut", "Set"))

    def sd(self,shut):
        h = self.lineEdit.text()
        m = self.lineEdit_2.text()
        if self.flag:
            self.flag = False
            try:
                os.popen('at '+h+':'+m+' shutdown -s')
                self.label_4.setText('Success! the system will shutdown at today '+h+':'+m+'.')
                self.pushButton.setText('Remove all')
                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('Success! already removed~')
                self.pushButton.setText('Set')
                self.lineEdit.clear()
                self.lineEdit_2.clear()
            except:
                self.label_4.setText('Something is wrong~')
        
if __name__ == '__main__':   
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_shut()
    ui.setupUi(Form) 
    Form.show()
    sys.exit(app.exec_())

到此這篇關(guān)于Python實(shí)現(xiàn)windows自動(dòng)關(guān)機(jī)功能的文章就介紹到這了,更多相關(guān)Python windows自動(dòng)關(guān)機(jī)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Flask數(shù)據(jù)庫(kù)遷移簡(jiǎn)單介紹

    Flask數(shù)據(jù)庫(kù)遷移簡(jiǎn)單介紹

    這篇文章主要為大家詳細(xì)介紹了Flask數(shù)據(jù)庫(kù)遷移簡(jiǎn)單工作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Python開(kāi)發(fā)中“切片創(chuàng)建副本但未賦值,以為修改原對(duì)象”的問(wèn)題解決方法

    Python開(kāi)發(fā)中“切片創(chuàng)建副本但未賦值,以為修改原對(duì)象”的問(wèn)題解決方法

    Python開(kāi)發(fā)中切片操作容易導(dǎo)致"修改原對(duì)象"的誤解,本文詳細(xì)分析了這一常見(jiàn)陷阱,通過(guò)典型場(chǎng)景復(fù)現(xiàn)問(wèn)題,解釋切片表達(dá)式產(chǎn)生新對(duì)象的底層機(jī)制,并給出正確修改原對(duì)象或保存副本的操作方法
    2026-06-06
  • python命令行執(zhí)行方法及技巧分享

    python命令行執(zhí)行方法及技巧分享

    這篇文章主要介紹了Python編程中使用命令行工具的基本操作和進(jìn)階技巧,通過(guò)編寫(xiě)Python腳本,理解Python解釋器,以及在命令行中執(zhí)行腳本,可以實(shí)現(xiàn)數(shù)據(jù)處理和系統(tǒng)任務(wù)的自動(dòng)化,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-04-04
  • python開(kāi)發(fā)之函數(shù)定義實(shí)例分析

    python開(kāi)發(fā)之函數(shù)定義實(shí)例分析

    這篇文章主要介紹了python開(kāi)發(fā)之函數(shù)定義方法,以實(shí)例形式較為詳細(xì)的分析了Python中函數(shù)的定義與使用技巧,需要的朋友可以參考下
    2015-11-11
  • Windows下Sqlmap環(huán)境安裝教程詳解

    Windows下Sqlmap環(huán)境安裝教程詳解

    這篇文章主要介紹了Windows下Sqlmap環(huán)境安裝,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • python使用百度文字識(shí)別功能方法詳解

    python使用百度文字識(shí)別功能方法詳解

    在本篇文章里小編給大家整理的是關(guān)于python怎么使用百度文字識(shí)別功能的相關(guān)知識(shí)點(diǎn),有興趣的朋友們參考下。
    2019-07-07
  • Python SSL證書(shū)驗(yàn)證問(wèn)題解決方案

    Python SSL證書(shū)驗(yàn)證問(wèn)題解決方案

    這篇文章主要介紹了Python SSL證書(shū)驗(yàn)證問(wèn)題解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Python實(shí)用工具之實(shí)現(xiàn)PDF轉(zhuǎn)DOCX文檔

    Python實(shí)用工具之實(shí)現(xiàn)PDF轉(zhuǎn)DOCX文檔

    pdf2docx作為第三方包,提供了非常優(yōu)秀的功能,僅僅幾行代碼就可以完成PDF轉(zhuǎn)換為DOCX的工作,所以本文就來(lái)利用pdf2docx實(shí)現(xiàn)PDF轉(zhuǎn)DOCX文檔功能吧
    2023-12-12
  • python提取字典key列表的方法

    python提取字典key列表的方法

    這篇文章主要介紹了python提取字典key列表的方法,涉及Python中keys方法的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • TensorFlow2基本操作之合并分割與統(tǒng)計(jì)

    TensorFlow2基本操作之合并分割與統(tǒng)計(jì)

    這篇文章主要介紹了TensorFlow2基本操作之合并分割與統(tǒng)計(jì),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09

最新評(píng)論

许昌市| 涞源县| 开远市| 兴山县| 永城市| 北川| 锡林浩特市| 蒲江县| 科尔| 七台河市| 澄江县| 二手房| 抚顺县| 阳泉市| 莆田市| 嘉兴市| 高碑店市| 辽阳县| 洞头县| 岑溪市| 藁城市| 阿瓦提县| 阿城市| 芮城县| 博客| 临桂县| 泰安市| 孝昌县| 信阳市| 巩义市| 宜兰市| 云霄县| 固原市| 丹巴县| 昌图县| 德昌县| 交城县| 信宜市| 丰镇市| 惠州市| 富平县|