极简屏保-python-tkinter

from ctypes import *
tfcglyyn = windll.shell32.IsUserAnAdmin()
user32 = windll.LoadLibrary("C:\\Windows\\System32\\user32.dll")
try:
    import win32api, win32gui
    ct = win32api.GetConsoleTitle()
    hd = win32gui.FindWindow(0,ct)
    win32gui.ShowWindow(hd,0)
except:pass
#——————————————————————————————————————————————————————————————————————
#输入数据模块

def enternpw():
    n = e("Enter time.")
    pw = e('Enter Password.(None:close this msg or press "OK")')
    tfc = e("是否完全锁定?(Y/N)")
    if tfc == "Y":
        tfc = True
    else:
        tfc = False
    return n,pw,tfc

#——————————————————————————————————————————————————————————————————————
import tkinter as tk,os
from time import sleep as sl
from easygui import enterbox as e,msgbox as msg,buttonbox as bt
from os import popen as p,_exit as _e
from random import randint as rrdt
stst = False
pwst = False
shutdownTF = bt("是否关机","",("是,计时结束立刻关机","是,输入密码后关机","否"))
if "立刻" in shutdownTF:
    shutdownTF = 1
elif "后" in shutdownTF:
    shutdownTF = 2
else:
    shutdownTF = 0

while not stst:
    n,pw,tfc = enternpw()
    if n == "" or n == None:
        msg("The parameter is wrong, please re-enter!","ok","Error!")
        continue
    else:
        n = int(n)
    if pw == "" or pw == None:
        pwst = True
        stst = True
    else:
        stst = True
        

def dw():
    pass
window = tk.Tk()
wh = str(window.winfo_screenwidth())
ht = str(window.winfo_screenheight())
window.geometry(wh + "x" + ht + "+0+0")
window.resizable(0,0)
window.config(bg = "black")
window.config(cursor="none")
window.wm_attributes('-topmost',1)
window.attributes("-alpha",0.9)
window.overrideredirect(True)
window.protocol("WM_DELETE_WINDOW",dw)
tt = tk.Label(window,text = "loading...",font = ("仿宋",20),fg = "blue",bg = "black")
tt.place(x = 0,y = 0)

sdzt = tk.Label(window,text = ("锁定状态:" + str(tfc)),font = ("仿宋",17),fg = "green",bg = "black")
sdzt.place(x = 0,y = 50)
wnlb = tk.Label(text = "Warning:请使用cmd运行此程序,否则无法锁定!",bg = "black",fg = "orange",font = ("仿宋",10))

#p("taskkill -f -im explorer.exe")
for i in range(n,0,-1):
    t = str(i % 60)
    m = str(i // 60 % 60)
    h = str(i //60 // 60)
    tt.config(text = "<time>: " + h + " 小时 " + m + " 分钟 " + t + " 秒后解除")
    if tfc:
        if tfcglyyn == 1:
            user32.BlockInput(True)
            sdzt.config(text = "锁定状态:键鼠完全锁定",fg = "red")
        else:
            sdzt.config(text = "锁定状态:键鼠未锁定",fg = "orange")
            wnlb.place(x = 0,y = 90)
    else:
        sdzt.config(text = "锁定状态:键鼠未锁定",fg = "green")
    window.update()
    sl(1)

def unsd():
    def unsdcm():
        os.popen("shutdown -a")
        win.destroy()
    win = tk.Tk()
    win.geometry("50x20+0+0")
    win.title("关机")
    win.resizable(0,0)
    win.wm_attributes('-topmost',1)
    win.config(bg = "black")
    tk.Button(win,text = "取消关机",font = ("",5),command = unsdcm,bg = "black",fg = "white",activebackground = "gray").pack()
    win.mainloop()
    
def delwm(event = None):
    def exitwm():
        import os
        tt.destroy()
        tk.Label(window,text = "EXIT...",bg = "black",fg = "white",font = ("",20)).place(x = 0,y = 0)
        window.update()
        sl(rrdt(5,15) / 10)
        window.destroy()
        tfpw = True
        if shutdownTF == 2:
            os.popen("shutdown -h")#os.popen("shutdown -s -t 10")
            ###########################################################
            unsd()

    if pwst == False:
        tk.Label(window,text = "Enter Password.( " + str(len(pw)) + " character)",bg = "black",fg = "white").pack()
        epy = tk.Entry(window)
        epy.pack()
        clbt.destroy()
        tfpw = False
        while not tfpw:
            window.update()
            if epy.get() == pw:
                exitwm()
            else:
                sl(0.1)
                continue
        _e(0)
    else:
        exitwm()
        
window.update()

clbt = tk.Button(window,text = "CLOSE",command = delwm)
clbt.pack()
window.config(cursor="arrow")
user32.BlockInput(False)
sdzt.config(text = "锁定状态:键鼠未锁定",fg = "green")
tt.config(text = "可以解除!")
window.bind("<Escape>",delwm)
if shutdownTF == 1:
    os.popen("shutdown -s -t 10")
    unsd()



如果发现有任何错误或者建议,请不吝赐教。本项目的代码存在一些漏洞和不足之处,非常欢迎广大网友能够提出批评和指正。您的每一条建议都将成为我们改进和完善代码的动力。在此感谢大家的支持!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值