There is a certain table on the basis of Treeview ()

Double-clicking on the row of this table displays a table with a detailed view of the elements of the row (since some cells can contain up to 1000 characters) and the ability to edit:

def onDoubleClick(root, event, table, identer): # Вывод окна просмотра задачи по двойному щелчку item = table.identify("item", event.x, event.y) taskview = table.item(item, "values") advanceDict = dict(zip(identer, taskview)) adnvanceViewForm = Toplevel(root) adnvanceViewForm.grab_set() adnvanceViewForm.focus_set() tabForm = Frame(adnvanceViewForm) butForm = Frame(adnvanceViewForm) tabForm.pack(side=TOP, expand=YES, fill=BOTH) butForm.pack(side=TOP, expand=YES, fill=BOTH) advanceVars = {} for (rowx, value) in enumerate(identer): lab = Label(tabForm, text=value) txt = Text(tabForm, font=('Helvetica', 10), width=70, height=2, wrap=WORD) txt.insert(1.0, advanceDict[value]) # Вставляем данные advanceVars[value] = txt.get(1.0, END).strip() # Извлекаем данные lab.grid(row=rowx, column=0) txt.grid(row=rowx, column=1) print(advanceDict) # Для сравнения словарей в stdout print(advanceVars) # Для сравнения словарей в stdout deleteButtn = Button(butForm, text="Удалить запись", command=lambda: deleteTask(adnvanceViewForm, cursor, taskview[0])) deleteButtn.pack(side=RIGHT) editButton = Button(butForm, text="Сохранить изменения", command=lambda: advanceEditButton(cursor, advanceVars)) editButton.pack(side=LEFT) 

We correct some element, click the save button, but no changes are made. The problem lies in the fact that insert inserts data from the dictionary, and get immediately collects them into a new dictionary. That is, the output dictionary is formed before making changes.

How can you organize data retrieval, only after making changes? I suspect that this action should be tied to the editButton button, but how to organize a detour around all Text widgets?

    1 answer 1

    The decision was rather strange. Instead of the extracted value, we put the variable itself in the dictionary. It was:

     advanceVars[value] = txt.get(1.0, END).strip() 

    It became:

     advanceVars[value] = txt 

    And in order to write the changed data, it is necessary in the definition of the function "advanceEditButton" to prescribe something like:

     def advanceEditButton(*args): newDict = {} for (key, value) in advanceVars.items(): newDict[key] = value.get(1.0, END).strip() 

    The newDict dictionary will contain already changed data. In other words, it seems to me that get () should have been used outside the widget's build cycle. : /