您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要讲解了“如何使用Python实现windows倒计时锁屏功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用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()
感谢各位的阅读,以上就是“如何使用Python实现windows倒计时锁屏功能”的内容了,经过本文的学习后,相信大家对如何使用Python实现windows倒计时锁屏功能这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。