
Python,速成心法
敲代码,查资料,问Ai
练习,探索,总结,优化

★★★★★博文创作不易,我的博文不需要打赏,也不需要知识付费,可以白嫖学习编程小技巧。使用代码的过程中,如有疑问的地方,欢迎大家指正留言交流。喜欢的老铁可以多多点赞+收藏分享+置顶,小红牛在此表示感谢。★★★★★
------★Python练手项目源码★------
Python项目99:Tkinter十六进制颜色对照表2.0(140种颜色)
Python项目94:全球疫情模拟数据可视化大屏(dash+plotly+pandas)
Python项目91:绘制红楼梦人物关系图(NetworkX+Matplotlib)
Python项目89:NetworkX最短路径规划(城市交通)
Python项目88:文件备份与压缩系统2.0(tkinter+shutil+zipfile)
Python项目86:增强版画板2.0(tk.Canvas)
Python项目81:Excel工作表批量重命名工具1.0(tkinter+openpyxl)
Python项目78:学生成绩分析系统(Tkinter+SQLite3)
Python项目77:模拟炒股训练系统3.0(Mplfinance+tkinter)
Python项目76:员工排班表系统1.0(tkinter+sqlite3+tkcalendar)
Python项目74:多线程数据可视化工具2.0(tkinter+matplotlib+mplcursors)
Python项目73:自动化文件备份系统1.0(tkinter)
Python项目源码71:药品管理系统1.0(tkinter+sqlite3)
Python项目源码69:Excel数据筛选器1.0(tkinter+sqlite3+pandas)
Python项目源码63:病历管理系统1.0(tkinter+sqlite3+matplotlib)
Python源码62:酒店住房管理系统1.0(tkinter+sqlite3)
Python项目源码57:数据格式转换工具1.0(csv+json+excel+sqlite3)
Python项目源码56:食堂饭卡管理系统1.0(tkinter+splite3)
Python项目源码54:员工信息管理系统2.0(tkinter+sqlite3)
Python项目源码52:模拟银行卡系统1.0(账户管理、存款、取款、转账和交易记录查询)
Python项目源码50:理发店会员管理系统1.0(tkinter+sqlite3)
Python项目源码48:正则表达式调试工具3.0(tkinter+re+requests)
Python项目源码44:图书管理系统1.0(tkinter+sqlite3)
Python项目源码42:仓库商品管理系统1.0(tkinter+sqlite3+Excel)
Python项目源码40:字符串处理工具(tkinter+入门练习)
Python项目源码39:学生积分管理系统1.0(命令行界面+Json)
Python项目源码35:音乐播放器2.0(Tkinter+mutagen)
Python项目源码33:待办事项列表应用2.0(命令行界面+Json+类)
Python项目32:订单销售额管理系统1.0(Tkinter+CSV)
Python项目源码29:学生缴费管理系统(Tkinter+CSV)
Python项目28:设计日志管理系统2.0(Tkinter+Json)
以下是一个使用 Python 和 Tkinter 实现的锁屏程序。它会全屏覆盖屏幕,并需要输入正确密码才能解锁。
2.使用说明

↓ 完整源码如下 ↓
# -*- coding: utf-8 -*-# @Author : 小红牛# 微信公众号:wdPythonimport tkinter as tkfrom tkinter import messagebox# 预设密码(可修改为其他字符串)PASSWORD = "123456"def check_password():"""检查输入的密码是否正确"""if entry.get() == PASSWORD:root.destroy() # 密码正确,关闭锁屏窗口else:# 密码错误:清空输入框,显示错误提示entry.delete(0, tk.END)lbl_error.config(text="密码错误,请重新输入!")entry.focus()def on_enter(event=None):"""按回车键时触发验证"""check_password()def block_keys(event):"""阻止部分可能导致退出的系统快捷键(可选)"""# 阻止 Alt+F4if event.keysym == "F4" and event.state & 0x0004:return "break"# 阻止 Alt+Tab 等切换窗口(效果有限)if event.keysym == "Tab" and event.state & 0x0004:return "break"# 创建主窗口root = tk.Tk()root.title("锁屏程序")root.attributes("-fullscreen", True) # 全屏root.attributes("-topmost", True) # 始终置顶root.overrideredirect(True) # 去除标题栏和边框# 可选:设置背景色或背景图片root.configure(bg="#2c3e50")# 阻止特定系统快捷键(非完美,但可增加难度)root.bind("<Alt-F4>", block_keys)root.bind("<Alt-Key>", block_keys) # 简单阻止 Alt 组合键# 创建主框架,用于居中放置控件main_frame = tk.Frame(root, bg="#2c3e50")main_frame.place(relx=0.5, rely=0.5, anchor="center")# 提示标签lbl_title = tk.Label(main_frame, text="屏幕已锁定", font=("楷体", 28, "bold"),fg="white", bg="#2c3e50")lbl_title.pack(pady=(0, 20))# 密码输入框entry = tk.Entry(main_frame, font=("楷体", 18), show="*", width=15,justify="center")entry.pack(pady=10)entry.focus_set() # 自动获取焦点# 确认按钮btn_unlock = tk.Button(main_frame, text="解锁", font=("楷体", 14),command=check_password, width=10, bg="#3498db", fg="white")btn_unlock.pack(pady=10)# 错误信息标签lbl_error = tk.Label(main_frame, text="", font=("楷体", 12),fg="#e74c3c", bg="#2c3e50")lbl_error.pack()# 绑定回车键root.bind("<Return>", on_enter)# 阻止用户通过任务管理器等方式强制关闭(仅提示,无法完全阻止)def on_closing():messagebox.showwarning("提示", "请输入密码解锁后退出!")root.protocol("WM_DELETE_WINDOW", on_closing)# 进入主循环root.mainloop()
完毕!!感谢您的收看
------★★历史博文集合★★------
