Python打工人必备之windows倒计时锁屏功能的实现
作者:木木子学python 发布时间:2021-01-18 04:21:21
标签:Python,windows,倒计时,锁屏
前言
又见面了,小伙伴儿们,发现最近大家喜欢看一些简单的小案例?!
咳咳,下面进入正题。
每个人的电脑里都会有不想让别人知道的隐私,或者是上班时间偷偷摸鱼怕被发现的小秘密。
那怎么办?就干脆把隐私锁起来!从源头上杜绝被他人 * 自己的隐私。
实现思路
1)主要介绍了python实现windows倒计时锁屏功能,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下:
python实现实windows倒计时锁屏功能
# 倒计时锁屏
import time
from ctypes import *
def closewindows(closetime):
while closetime>0:
print(closetime)
time.sleep(1)
closetime-=1
user32 = windll.LoadLibrary('user32.dll')
user32.LockWorkStation()
if __name__ == "__main__":
closewindows(3)
2)知识点扩展
Python在windows锁屏的代码
C:\Users\HAS>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> user32 = windll.LoadLibrary('user32.dll')
>>> user32.LockWorkStation()
3)python实现倒计时小工具
#!/usr/bin/env python
# coding=utf-8
import threading
import time
import Queue
from Tkinter import *
import tkMessageBox
import logging
logging.basicConfig(level=logging.INFO)
## Communication queue
commQueue = Queue.Queue()
g_time = 0
## Function run in thread
def timeThread():
global g_time
g_time = timeVar.get() * 60
while 1:
logging.info("线程放入队列:%d".decode("utf-8") % g_time)
commQueue.put(g_time)
try:
root.event_generate('<<TimeChanged>>', when='tail')
except TclError:
break
time.sleep(1)
g_time -= 1
if g_time==-1:
begin_btn["fg"] = "black"
clockVar.set("开始计时")
break
def timeChanged(event):
x = commQueue.get()
logging.info("获取队列:%d".decode("utf-8") % x)
minits = x//60
seconds = x%60
s = "剩余时间 {:02}:{:02}".format(minits, seconds)
begin_btn["fg"] = "blue"
clockVar.set(s)
if x==0:
tkMessageBox.showinfo("提醒","时间已到")
def clock_func(*args):
global g_time
if threading.activeCount()>1:
g_time = timeVar.get() * 60
else:
th=threading.Thread(target=timeThread)
th.start()
## Create main window
root = Tk()
root.title("计时工具")
root.geometry("180x95-0-45")
root.resizable(width=FALSE,height=FALSE)
root.wm_attributes("-topmost",1)
frame = Frame(root)
frame.pack()
Label(frame,text="设定时间间隔").grid(row=1,column=2)
timeVar = IntVar()
clockVar = StringVar()
time_entry = Entry(frame, textvariable=timeVar, width=8)
time_entry["justify"] = "center"
time_entry.grid(row=2,column=2,sticky="W,E")
begin_btn = Button(frame,textvariable=clockVar,command=clock_func)
begin_btn.grid(row=3,column=2)
timeVar.set(8)
begin_btn["fg"] = "black"
clockVar.set("开始计时")
for child in frame.winfo_children():
child.grid_configure(pady=3)
time_entry.focus()
root.bind('<<TimeChanged>>', timeChanged)
root.bind("<Return>",clock_func)
root.mainloop()
好啦,今天的内容就到这里正是结束,再也不用担心自己的电脑屏幕一直亮着了~自动倒计时锁屏, 你值得拥有!
来源:https://juejin.cn/post/7217346593502232633


猜你喜欢
- 我就废话不多说了,直接上代码吧!import datetimedef find_close(arr, e): start_time = da
- 如果要写一个程序,让x1为1,x2为2,然后直到x100为100,你会怎么做?在C这种静态语言里,变量名这个标识符实际上会被编译器直接翻译成
- 对图片进行resize、裁剪、旋转、翻转图片处理时常用的手段有resize、裁剪、旋转、翻转,简单介绍一下python中怎么利用PIL库和t
- 1、利用Python中的random模块中的choice方法random.choice()可以从任何序列,比如list列表中,选取一个随机的
- 本文介绍了深入理解ES6中let和闭包,分享给大家,具体如下:在开始本文之前我们先来看一段代码for(var i=0;i<10;i++
- 在做开发的朋友特别是和mysql有接触的朋友会碰到有时mysql查询很慢,当然我指的是大数据量百万千万级了,不是几十条了,下面我们来看看解决
- 本文实例为大家分享了Bootstrap实现渐变顶部固定自适应导航栏的具体代码,供大家参考,具体内容如下具体代码如下所示:<!DOCTY
- 前言elasticsearch-dsl是基于elasticsearch-py封装实现的,提供了更简便的操作elasticsearch的方法。
- 一、创建模型类:# -*- coding: utf-8 -*-from __future__ import unicode_literals
- 在 Python 中,集合(set)是一种无序且不重复的集合类型,它是由花括号 {} 括起来的一组元素。如果你想向集合中添加一个元素,你可以
- 准备工作(导入库、导入数据)import pandas as pdimport matplotlib.pyplot as pltimport
- 我看见朋友可以把数据库的记录输出到页面表格上去,觉得很有用。这是怎么做的啊?见下:dbtable.asp<html><he
- 简介mysql应该是我们在日常工作中使用到的一个非常普遍的数据库,虽然mysql现在是oracle公司的,但是它是开源的,市场占有率还是非常
- 本文实例讲述了python统计文本文件内单词数量的方法。分享给大家供大家参考。具体实现方法如下:# count lines, sentenc
- 阅读上一篇:javascript面向对象编程(三)继承是面向对象语言中的一个重要概念,现在我们来探讨一下继承。在网上搜一下javascrip
- 目录用Python实现定时任务用Python实现定时任务的四种方法利用while True: + sleep()实现定时任务利用thread
- 如下所示:import datetime #获取两个日期间的所有日期 def getEveryDay(begin_date,end_date
- 引言今天我们来分享一个 Python 领域的神级第三方库 -- pycallgraph,通过该库并结合 graphviz 工具,就可以非常方
- 直接使用word文档已经难不倒大家了,有没有想过用python构建一个word文档写点文章呢?当然这个文章的框架需要我们用代码一点点的建立,
- Javascript 正常取来源网页的URL只要用: document.referrer就可以了!但,如果来源页是Jav