本帖最后由 tonado 于 2020-3-4 19:19 编辑
脚本来自网上,我修改了一下适应Python3版本,需要用到nircmd这个小工具,可以去http://www.nirsoft.net/选择对应版本下载,提供个64位的。
功能很简单,我是用来控制儿子看电脑的时间,比如工作时间设置成20分钟,休息5分钟。程序就在开始20分钟后关闭屏幕5分钟,期间无法激活屏幕(当然重启系统肯定能解决。)。
[Python] 纯文本查看 复制代码 import time
import os
import platform
work_time = int(input("请输入你需要工作的时间 [分钟]: "))
break_time = int(input("请输入你需要休息的时间 [分钟]: "))
break_time = break_time*60
start =input("是否开始执行yes/no [y/n]: ")
os_str = platform.system()
work_stage = 0
while (start == 'y'):
for i in range(work_time):
print( '开始工作 ', work_time-i, '分钟')
time.sleep(60)
# During the break time
# the display should always be closed
# if rewake by mouse, it will be closed again
insleep = 1
start_time = time.time()
while (insleep):
if os_str == "Windows":
# Under windows, nircmd should be installed first
# The usage can reference: www.nirsoft.net/utils/nircmd.html
os.system("nircmd.exe monitor off")
elif os_str == "Linux":
os.system("xset dpms force off")
end_time = time.time()
if end_time-start_time > break_time:
insleep = 0
if os_str == "Linux":
os.system("xset dpms force on")
elif os_str == "Windows":
os.system("nircmd.exe monitor on")
work_stage = work_stage + 1
print ("================\n工作时间段 {} \n================\n".format(work_stage))
start = input("是否继续yes/no [y/n]: ") |