<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://itecfun.com/extern.php?action=feed&amp;tid=3349&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[个人知识管理站 / python gui之tkinter事件处理]]></title>
		<link>http://www.itecfun.com/viewtopic.php?id=3349</link>
		<description><![CDATA[python gui之tkinter事件处理 最近发表的帖子。]]></description>
		<lastBuildDate>Sun, 27 May 2018 03:38:57 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[python gui之tkinter事件处理]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3608#p3608</link>
			<description><![CDATA[<p>python gui之tkinter事件处理<br />事件一览表<br />事件&#160; &#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; 代码&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; 备注<br />鼠标左键单击按下&#160; &#160; 1/Button-1/ButtonPress-1&#160; &#160;&#160; <br />鼠标左键单击松开&#160; &#160; ButtonRelease-1&#160; &#160;&#160; <br />鼠标右键单击&#160; &#160; 3&#160; &#160;&#160; <br />鼠标左键双击&#160; &#160; Double-1/Double-Button-1&#160; &#160;&#160; <br />鼠标右键双击&#160; &#160; Double-3&#160; &#160;&#160; <br />鼠标滚轮单击&#160; &#160; 2&#160; &#160;&#160; <br />鼠标滚轮双击&#160; &#160; Double-2&#160; &#160;&#160; <br />鼠标移动&#160; &#160;&#160; &#160; &#160; &#160; &#160;B1-Motion&#160; &#160;&#160; <br />鼠标移动到区域&#160; &#160; Enter&#160; &#160;&#160; <br />鼠标离开区域&#160; &#160; Leave&#160; &#160;&#160; <br />获得键盘焦点&#160; &#160; FocusIn&#160; &#160;&#160; <br />失去键盘焦点&#160; &#160; FocusOut&#160; &#160;&#160; <br />键盘事件&#160; &#160; &#160; &#160; &#160; Key&#160; &#160;&#160; <br />回车键&#160; &#160;&#160; &#160; &#160; &#160; &#160;Return&#160; &#160;&#160; <br />控件尺寸变&#160; &#160;&#160; &#160; Configure&#160; &#160; </p><p>响应时间<br />提前响应<br />ttk treeview的TreeviewSelect事件是提前的，即你选中了某行，通过treeview.selection()[0]得到的就是这一样。 </p><p>延后相应<br />比如ttk的treeview是的单击的情况，单击的行被选中了，但是通过 treeview.selection()[0]得到的却不是选中的行！而是之前选中的行。可以参考下这里。</p><p>响应函数<br />event_handler(event,*args)</p><p>event参数<br />event 参数有以下属性：</p><p>[&#039;__doc__&#039;, &#039;__module__&#039;, &#039;char&#039;, &#039;delta&#039;, &#039;height&#039;, &#039;keycode&#039;, &#039;keysym&#039;, &#039;keysym_num&#039;, &#039;num&#039;, &#039;send_event&#039;, &#039;serial&#039;, &#039;state&#039;, &#039;time&#039;, &#039;type&#039;, &#039;widget&#039;, &#039;width&#039;, &#039;x&#039;, &#039;x_root&#039;, &#039;y&#039;, &#039;y_root&#039;]</p><p>Event Attributes<br />widget<br />The widget which generated this event. This is a valid Tkinter widget instance, not a name. This attribute is set for all events.</p><p>x, y<br />鼠标当前的相对位置，以像素为单位。</p><p>比如，ttk treeview 有个通过y坐标定位行的方法：identify_row(self, y)</p><br /><p>x_root, y_root<br />鼠标当前的绝对位置（相对于设备的左上角）。以像素为单位。</p><p>char<br />字符（键盘事件中才有）， 类型是字符串。</p><p>keysym<br />The key symbol (keyboard events only).</p><p>键符（键盘事件中才有）</p><p>keycode<br />键码 (键盘事件中才有).</p><p>num<br />按钮号码（鼠标事件中才有）1-左键/2-中/3-右</p><p>width, height<br />widget的新尺寸，以像素为单位(Configure events only).</p><p>type<br />&#160; &#160; &#160; &#160; 事件类型<br />&#160; &#160; &#160; &#160; 1---<br />&#160; &#160; &#160; &#160; 2---<br />&#160; &#160; &#160; &#160; 3---<br />&#160; &#160; &#160; &#160; 4---鼠标<br />更多资料参考这里。<br />绑定事件<br />控件.bind(&#039;&lt;事件代码&gt;&#039;,event_handler)<br />适用于大多数控件。此外还有bind_all方法。</p><p>控件.protocal(&#039;事件代码&#039;, event_handler)<br />这种情况的控件，必需是顶层窗口或者root容器。</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Sun, 27 May 2018 03:38:57 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3608#p3608</guid>
		</item>
	</channel>
</rss>
