繁体   English   中英

如何确保在FocusOut上保存tkinter条目的内容?

[英]How can I make sure the content of a tkinter entry is saved on FocusOut?

我有一个使用<FocusOut>绑定的应用程序,可以自动将Entry的编辑保存到列表中。

使用TAB导航条目或单击另一个条目时保存Entry文本没有问题,但是如果我更改一个条目上的文本然后如果我鼠标单击另一个框架中的ListBox<FocusOut>不适用于最后选择的条目,并且其中的信息未注册。

如何在不借助GUI上的“ Save按钮的情况下避免这种情况? 对于ListBox中的每个选项,都有不同的Entry框,因此用户必须多次按Save按钮。 我想避免这种情况。

实时编辑/保存文本

看起来您想要实时获取更新的文本。 在这种情况下我做的是使用'KeyRelease' 简单,有效的enrtry特定,并立即工作。

在概念上:

win = Tk()
def dosomething(*args):
    # update the corresponding text anywhere, save your text, whatever
    print(entry.get())

entry = Entry()
entry.bind("<KeyRelease>", dosomething)
entry.pack()

win.mainloop()

在此输入图像描述

在行动:

M
Mo
Mon
Monk
Monke
Monkey
Monkey 
Monkey e
Monkey ea
Monkey eat
Monkey eats
Monkey eats 
Monkey eats b
Monkey eats ban
Monkey eats ban
Monkey eats bana
Monkey eats banan
Monkey eats banana

暂无
暂无

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

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