python+Tkinter 中的光标事件处理
我正在构建一个代码,当用户将光标的焦点从一个条目小部件更改为任何地方时,我希望能够生成一个事件,例如另一个条目小部件,一个按钮......
到目前为止我只提出了绑定到 TAB 和鼠标单击的想法,尽管如果我将鼠标单击绑定到 Entry 小部件,我只会在 Entry 小部件内部时收到鼠标事件。
当小部件失去光标焦点时,如何完成生成事件?
提前致谢!
I'm building a code in which I'd like to be able to generate an event when the user changes the focus of the cursor from an Entry widget to anywhere, for example another entry widget, a button...
So far i only came out with the idea to bind to TAB and mouse click, although if i bind the mouse click to the Entry widget i only get mouse events when inside the Entry widget.
How can I accomplish generate events for when a widget loses cursor focus?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事件和<焦点离开> 是你想要的。 运行以下示例,当焦点位于条目小部件之一时,无论您单击还是按 Tab(或 Shift-Tab),您都会看到焦点进入和退出绑定。
The events <FocusIn> and <FocusOut> are what you want. Run the following example and you'll see you get focus in and out bindings whether you click or press tab (or shift-tab) when focus is in one of the entry widgets.
这不是 tkinter 特有的,也不是基于焦点的,但我在这里得到了类似问题的答案:
使用 python 检测窗口中的鼠标点击
我已经有一段时间没有做过任何 tkinter 了,但似乎有“FocusIn”和“FocusOut”事件。 您也许可以绑定并跟踪这些来解决您的问题。
从:
http://effbot.org/tkinterbook/tkinter-events-and-bindings。嗯
This isn't specific to tkinter, and it's not focus based, but I got an answer to a similar question here:
Detecting Mouse clicks in windows using python
I haven't done any tkinter in quite a while, but there seems to be "FocusIn" and "FocusOut" events. You might be able to bind and track these to solve your issue.
From:
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm