惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
G
GRAHAM CLULEY
Attack and Defense Labs
Attack and Defense Labs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
C
CXSECURITY Database RSS Feed - CXSecurity.com
量子位
T
The Blog of Author Tim Ferriss
Project Zero
Project Zero
Webroot Blog
Webroot Blog
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
A
About on SuperTechFans
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
Security Latest
Security Latest
S
Schneier on Security
W
WeLiveSecurity
K
Kaspersky official blog
有赞技术团队
有赞技术团队
Cyberwarzone
Cyberwarzone
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
G
Google Developers Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Schneier on Security
Schneier on Security
博客园_首页
博客园 - 司徒正美
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Check Point Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 箫笛

Tkinter - Entry 输入框组件 Tkinter - Button 组件 Tkinter - Label 组件 Tkinter - tk 变量 Tkinter - 几何管理器 Tkinter - 核心概念 Tkinter - 快速开始 Tkinter - 介绍 Python 编程 - 条件表达式 Python 编程 - 星号下划线参数释义 shell 编程 - shell 脚本的交互方式 Python insall - macOS 系统安装python的几种方式 Miniconda - Python 环境管理工具 Tkinter - Python GUI 开发 Python 编程 - 下划线命名的区别 Python 编程 - 元类编程 Python 编程 - 多重继承与MRO Python 编程 - 描述符协议 Python 编程 - 类型注解 Python 编程 - 生成器表达式 Python 编程 - 集合 Python 编程 - 装饰器 Python 编程 - 闭包 Python 编程 - 列表推导式 Python 编程 - 函数式编程 Python 编程 - lambda 函数 Python 编程 - 文件操作 Python 编程 - 输入与输出 Python 编程 - 面向对象编程 Python 编程 - 元组(tuple) Python 编程 - 字符串(str) Python 编程 - 字典(dict) Python 编程 - 列表(list) Python 编程 - 数据类型和数据结构 Python 编程 - 语句 Python 编程 - 函数 windows - WSL 的安装与使用 shell编程 - dialog 程序使用指南 FE Team - 如何做好前端代码审查 git 提交的撤销和恢复 React15 - redux-saga 如何在saga中实现轮询接口调用? React15 - React CSS Modules BEM命名实践 React15 - React 15 中 componentWillReceiveProps 为什么会多次调用, 同时componentDidUpdate 也会多次调用? React15 - React15类组件多次执行render方法的原因? React15 - React15应用中代码逻辑复用方案 React15 - React状态同步问题解决 React15 - React 15 中 React.pureComponent 的使用场景 React15 - React 15应用在页面渲染时会多次执行类组件的render 函数的原因 React15 - React 15 中能用 componetDidUpdate 代替 componentWillReceiveProps 吗? React15 - React 15 生命周期函数详解 React15 - 如何在React 15中实现自定义的事件订阅与发送(例如组件间通信) React15 - React15应用中的事件订阅和发送机制 React15 - CSS中的BEM规范 React15 - React CSS Modules BEM命名实践 React15 - 写sass 样式文件,嵌套的结构好,还是扁平的结构好? React15 - sass 中 @mixin 和 @extend 的区别是什么? React15 - React 15 应用 如何使用Css moudules 方式进行模块化开发 React15 - React15应用Sass使用指南 React15 - React 15 应用如何进行性能优化?
Tkinter - 事件与绑定
箫笛 · 2026-07-10 · via 博客园 - 箫笛

响应用户交互和系统事件


bind() 基础

widget.bind(sequence, callback, add=None) → funcid

bind_basics.py

label.bind("<Button-1>", lambda e: print(f"点击位置:{e.x},{e.y}"))
root.bind("<Control-s>", lambda e: save())
root.bind("<Escape>",    lambda e: root.destroy())

事件对象

属性 类型 说明
widget Widget 接收事件的控件
x, y int 鼠标相对于控件的位置
x_root, y_root int 鼠标相对于屏幕的位置
num int 鼠标按钮编号(1、2、3)
keysym str 键名(例如 "Return""a""F5"
char str 输入的字符(可能为空)
state int 修饰键位掩码(Shift、Ctrl、Alt)
delta int 滚动量(鼠标滚轮事件)
width, height int 新尺寸(配置事件)

鼠标事件

序列 触发时机
<Button-1> 鼠标左键按下
<Button-3> 鼠标右键按下
<ButtonRelease-1> 鼠标左键释放
<Double-Button-1> 鼠标左键双击
<B1-Motion> 按住左键时移动鼠标
<Motion> 鼠标移动(任意按键或无按键)
<Enter> / <Leave> 鼠标光标进入/离开控件
<MouseWheel> 鼠标滚轮滚动(event.delta

键盘事件

序列 说明
<Key> 任意按键按下
<Return> 回车键
<Escape> ESC 键
<Tab> / <BackSpace> / <Delete> Tab / 退格 / Delete
<Up> <Down> <Left> <Right> 方向键
<F1><F12> 功能键
<Control-s> Ctrl+S
<Control-Shift-Z> Ctrl+Shift+Z

虚拟事件

虚拟事件 触发时机
<<Cut>> <<Copy>> <<Paste>> 剪贴板操作
<<ComboboxSelected>> ttk.Combobox 选择变更
<<NotebookTabChanged>> ttk.Notebook 标签页切换
<<TreeviewSelect>> ttk.Treeview 行被选中
<<ListboxSelect>> Listbox 选择变更

after() —— 定时器

widget.after(ms, func=None, *args) → after_id

countdown.py

count = tk.IntVar(value=10)
label = ttk.Label(root, textvariable=count, font=("TkDefaultFont", 48))
label.pack(padx=40, pady=20)

def tick():
    n = count.get()
    if n > 0:
        count.set(n - 1)
        root.after(1000, tick)
    else:
        label.config(text="完成!")

root.after(1000, tick)