1

I have a table made of multiple entries in tkinter. When I change one entry I want to update all others. I have achieved this by binding all entries with a <FocusOut> function that refreshes the table. This works fines as long as I do not focus from one entry to another.

  • What works: I click on one entry, I type what I want, I click somewhere else in the window (except another entry) and everything updates fine. I can continue on.

  • What doesn't: I click on one entry, I type what I want and I click on another entry. This updates the table, but I can not type anything nor click on any other entry as long as I do not click first on a 'non entry' part of the frame. As if the <FocusOut> bound prevented me from focusing in to the next one.

I would like to either:

  • keep track of the next entry I click on in order to focus_force() it after the refresh has run.
  • or solve this problem with any other welcome suggestion.

Here is a simplified version of my code:

entries = {}

def table_refresh():
    for y, name in zip(list_y, list_names):
        insertion = "some value that is function of the other entries"
        entries[name] = tk.Entry(master)
        entries[name].place(x=x, y=y)
        entries[name].insert(0, insertion)
        entries[name].configure(**entry_params)
        entries[name].bind("<FocusOut>", on_focusout)

def on_focusout(event):
    table_refresh()
  • 1
    Does the posted code have wrong indentation as I think `on_focusout()` should not be a nested function inside `table_refresh()`. Also the for loop should not be inside `table_refresh()` function as well. – acw1668 Sep 29 '21 at 16:25
  • I have different tables and want a different `on_focusout` function for each, but for this example I agree. However the for loop inside the function is one way to refresh the table. Instead of building it and then updating everything everytime, I just construct it again. –  Sep 29 '21 at 16:50
  • 1
    When you go from one entry to another entry, new set of entries are created which overlay those old entries (including the currently focused entry). If you click on one of the new entries, the currently focused entry (hidden) lost focus and trigger the refresh and so repeat the above process again. That is the reason to what you said *"doesn't work"*. – acw1668 Sep 30 '21 at 01:04

0 Answers0