python gui之tkinter事件处理
2016-09-05 15:23
731 查看
事件 | 代码 | 备注 |
鼠标左键单击按下 | 1/Button-1/ButtonPress-1 | |
鼠标左键单击松开 | ButtonRelease-1 | |
鼠标右键单击 | 3 | |
鼠标左键双击 | Double-1/Double-Button-1 | |
鼠标右键双击 | Double-3 | |
鼠标滚轮单击 | 2 | |
鼠标滚轮双击 | Double-2 | |
鼠标移动 | B1-Motion | |
鼠标移动到区域 | Enter | |
鼠标离开区域 | Leave | |
获得键盘焦点 | FocusIn | |
失去键盘焦点 | FocusOut | |
键盘事件 | Key | |
回车键 | Return | |
控件尺寸变 | Configure |
响应时间
提前响应
ttk treeview的TreeviewSelect事件是提前的,即你选中了某行,通过treeview.selection()[0]得到的就是这一样。延后相应
比如ttk的treeview是的单击的情况,单击的行被选中了,但是通过 treeview.selection()[0]得到的却不是选中的行!而是之前选中的行。可以参考下这里。响应函数
event_handler(event,*args)event参数
event 参数有以下属性:['__doc__', '__module__', 'char', 'delta', 'height', 'keycode', 'keysym', 'keysym_num', 'num', 'send_event', 'serial', 'state', 'time', 'type', 'widget', 'width', 'x', 'x_root', 'y', 'y_root']
Event Attributes
widgetThe widget which generated this event. This is a valid Tkinter widget instance, not a name. This attribute is set for all events.
x, y
鼠标当前的相对位置,以像素为单位。
比如,ttk treeview 有个通过y坐标定位行的方法:identify_row(self, y)
x_root, y_root
鼠标当前的绝对位置(相对于设备的左上角)。以像素为单位。
char
字符(键盘事件中才有), 类型是字符串。
keysym
The key symbol (keyboard events only).
键符(键盘事件中才有)
keycode
键码 (键盘事件中才有).
num
按钮号码(鼠标事件中才有)1-左键/2-中/3-右
width, height
widget的新尺寸,以像素为单位(Configure events only).
type事件类型 1--- 2--- 3--- 4---鼠标更多资料参考这里。
绑定事件
控件.bind('<事件代码>',event_handler)
适用于大多数控件。此外还有bind_all方法。控件.protocal('事件代码', event_handler)
这种情况的控件,必需是顶层窗口或者root容器。相关文章推荐
- python gui之tkinter事件处理
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(text.insert/link各种事件)——Jason niu
- Python:GUI之tkinter学习笔记3事件绑定
- 27-python_GUI-布局管理-事件处理
- Python GUI:高级作图tkinter模块的常用函数基本的动画和事件绑定
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button展示图片事件/)——Jason niu
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)——Jason niu
- Python下用Tkinter进行GUI编程
- Java GUI之事件监听与处理的匿名类实现方法
- java心得--GUI事件处理
- GUi事件处理
- Java GUI编程中的事件处理机制详细讲解
- Python TKinter Gui: Toplevel window
- 使用Tkinter做python的GUI编程
- [Java GUI] 鼠标移动事件处理示例
- Java GUI编程中如何进行事件处理机制
- java心得--GUI事件处理
- Java GUI编程中的事件处理机制详细讲解
- Java GUI之事件监听与处理
- unity3d 鼠标事件穿透GUI的处理