Python 官方文档:入门教程 => 点击学习
这篇文章主要介绍了怎么使用python实现windows倒计时锁屏功能的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么使用Python实现windows倒计时锁屏功能文章都会有所收获,下面我们一起来看看吧。实
这篇文章主要介绍了怎么使用python实现windows倒计时锁屏功能的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么使用Python实现windows倒计时锁屏功能文章都会有所收获,下面我们一起来看看吧。
1)主要介绍了python实现windows倒计时锁屏功能
python实现实windows倒计时锁屏功能
# 倒计时锁屏import timefrom ctypes import *def closewindows(closetime):while closetime>0:print(closetime)time.sleep(1)closetime-=1user32 = windll.LoadLibrary('user32.dll')user32.LockWorkStation()if __name__ == "__main__":closewindows(3)
2)知识点扩展
Python在windows锁屏的代码
C:\Users\HAS>pythonPython 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]on win32Type "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-8import threadingimport timeimport Queuefrom Tkinter import *import tkMessageBoximport logginglogging.basicConfig(level=logging.INFO)## Communication queuecomMQueue = Queue.Queue()g_time = 0## Function run in threaddef timeThread():global g_timeg_time = timeVar.get() * 60while 1:logging.info("线程放入队列:%d".decode("utf-8") % g_time)commQueue.put(g_time)try:root.event_generate('<<TimeChanged>>', when='tail')except TclError:breaktime.sleep(1)g_time -= 1if g_time==-1:begin_btn["fg"] = "black"clockVar.set("开始计时")breakdef timeChanged(event):x = commQueue.get()logging.info("获取队列:%d".decode("utf-8") % x)minits = x//60seconds = x%60s = "剩余时间 {:02}:{:02}".format(minits, seconds)begin_btn["fg"] = "blue"clockVar.set(s)if x==0:tkMessageBox.showinfo("提醒","时间已到")def clock_func(*args):global g_timeif threading.activeCount()>1:g_time = timeVar.get() * 60else:th=threading.Thread(target=timeThread)th.start()## Create main windowroot = 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()
关于“怎么使用Python实现windows倒计时锁屏功能”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“怎么使用Python实现windows倒计时锁屏功能”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网Python频道。
--结束END--
本文标题: 怎么使用Python实现windows倒计时锁屏功能
本文链接: https://www.lsjlt.com/news/358009.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0