Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an app that uses <FocusOut> binding to automatically save the edits in an Entry to a list.

There is no problem saving the Entry text when using TAB to navigate through the Entries or when I click on another Entry, but If I change the text on one Entry and then if I mouse-click on a ListBox in another frame, <FocusOut> doesn't work on the last selected Entry and the information in it is not registered.

How can I avoid this without resorting to a Save button on the GUI? For every selection in the ListBox there are different Entry boxes, so the user would have to press the Save button numerous times. I would like to avoid that.

like image 676
Alexandru Antochi Avatar asked Sep 05 '25 03:09

Alexandru Antochi


1 Answers

Realtime edit / save text instead

It looks like you want to get the updated text realtime. What I do in such a case is use the 'KeyRelease' -binding. Simple, effective enrtry- specific and works instantly.

In concept:

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()

enter image description here

In action:

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
like image 161
Jacob Vlijm Avatar answered Sep 07 '25 15:09

Jacob Vlijm