首页 > 学院 > 开发设计 > 正文

[python]计算机使用过程中,眼睛强制休息

2019-11-14 17:48:46
字体:
来源:转载
供稿:网友

前言

现在的电脑族们,在使用电脑的过程中,常常忘记了时间的流逝,要么忙碌在电视剧的观看中,要么忙碌在工作中,要么忙碌在游戏中,往往忽视了对眼睛的正常保护,让眼睛能够在空闲的时候获得足够的休息时间。

我也是其中之一。

但当我发现自己的眼睛的疲劳程度在慢慢增加的时候,对于视力保护的需求也越来越迫切了。

于是,利用自己的小小编程技巧,利用python的简易性,实现了下面的“强制眼睛休息的脚本”,当设定的工作时间结束后,计算机的显示器会被强制关闭,如果用鼠标进行强制唤醒,显示器依然会随后快速关闭,直到设定的休息时间都过去以后,显示器才会开启。

具体实现如下

 1 """ 2 count down the time to close the display 3 Create by Zhong Xiewei 4 """ 5 import time 6 import os 7 import platform 8  9 work_time = int(raw_input("Enter your work time [min]: "))10 break_time = int(raw_input("Enter your break time [min]: "))11 break_time = break_time*6012 start = raw_input("Do you want start [y/n]: ")13 os_str = platform.system()14 15 work_stage = 016 while (start == 'y'):17     for i in range(work_time):18         PRint  'Remain ', work_time-i, 'min'19         time.sleep(60)20 21     # During the break time22     # the display should always be closed23     # if rewake by mouse, it will be closed again24     insleep = 125     start_time = time.time()26     while (insleep):27         if os_str == "Windows":28             # Under windows, nircmd should be installed first29             # The usage can reference: www.nirsoft.net/utils/nircmd.html30             os.system("nircmd.exe monitor off")31         elif os_str == "linux":32             os.system("xset dpms force off")33         end_time = time.time()34         if end_time-start_time > break_time:35             insleep = 036 37     if os_str == "Linux":38         os.system("xset dpms force on")39     elif os_str == "Windows":40         os.system("nircmd.exe monitor on")41 42     work_stage = work_stage + 143     print "================/nWork Stage ", work_stage,"/n================/n"44     start = raw_input("Do you want continue [y/n]: ")

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表