Press "Enter" to skip to content

Python写的一个保护眼睛程序

您是否有时候写代码或者工作的时候忘记了休息?让它提醒您休息吧 (强制锁屏哦)

from ctypes import *
import time
import math
import sys


rest_tm = 0
sel_unit = 1

d_sel = {"1": "分钟", "2": "小时"}
sel_unit = input(
"请选择时间隔时间类型:\n" "1:分钟" "2:小时\n"
)

if sel_unit not in d_sel:
    print("输入不正确\n");
    sys.exit()

work_tm = int(input("请输入工作时间\n"))
rest_tm = int(input("请输入休息时间\n"))
print("您的电脑将在", work_tm , d_sel[sel_unit], "后锁定\n")

second_work_tm = int(math.pow(60 ,int(sel_unit)) * work_tm)   ###工作时间总秒数
do_second_work_tm = second_work_tm

second_tm = int(math.pow(60 ,int(sel_unit)) * rest_tm)   ###休息时间总秒数

while True:
    while do_second_work_tm > 0:
        do_second_work_tm -= 1
        time.sleep(1)
        if do_second_work_tm < 30 :
            print("休息时间还有", do_second_work_tm , "秒就到了\n")

    ##间隔时间到
    do_second_work_tm = second_work_tm
    sel_opt = int(input("请选择您的操作 1:立即休息  2:下次休息  3:退出程序\n"))
    if sel_opt not in [1 , 2 , 3]:
        print("输入异常")
        sys.exit()
    if sel_opt == 1:
        print("立即休息,我会为您锁定屏幕 届时您不能进行任何操作\n")

        #锁定屏幕
        windll.user32.BlockInput("true")
        windll.user32.SetCursorPos(100, 100)  

        #休息休息===========================
        while second_tm > 0:
            second_tm -= 1
            time.sleep(1)
            if second_tm < 60:
                print("还有", second_tm , "秒回到工作\n")

        #释放屏幕
        windll.user32.BlockInput(0)
        print("回到工作状态 开心工作吧\n")
    if sel_opt == 2:
        print("您选择了下次休息,眼睛时心灵的窗户要保护好哦\n")
        continue
    if sel_opt == 3:
        sys.exit()
发表评论