简体   繁体   English

Tkinter:取消选择输入框时如何获取事件监听器?

[英]Tkinter: How to get event listener when entry box is deselected?

Just the title.只是标题。 I have an entry box that needs to be rounded to 10, but I want it to happen the moment another entry box is selected.我有一个需要四舍五入到 10 的输入框,但我希望它在选择另一个输入框的那一刻发生。

The only event listener I can find to do with tkinter entry boxes is attatching a StringVar and tracing it, but that doesn't seem to do what I want here as I don't want the changes to happen while typing.我能找到的唯一与 tkinter 输入框有关的事件监听器是附加一个 StringVar 并跟踪它,但这似乎并没有达到我想要的效果,因为我不希望在键入时发生更改。

You are looking for the <FocusOut> event.您正在寻找<FocusOut>事件。

def some_func(event):
    print("The entry has lost focus")
entry = tk.Entry(...)
entry.bind("<FocusOut>", some_func)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM