My application is a form which populates its fields from a database. I am in the process of writing the function that navigates between these records. I am having problems writing my "next record" function.
At any given time, the "Current Record" showing on the screen is in a variable current_record.
def next_record(current_record):
current_index = current_record.index
current_record = Competitor(competitors[current_index + 1], current_index + 1)
print(current_record.index)
populate_form(current_record)
And my button calling this function:
action_button_6 = tkinter.Button(group_buttons, text='>>', width=5,
command=lambda: next_record(current_record))
Although the function does its job and loads the new record into the form, it does not reassign "current_record" to the new competitor as show in the third line of the function.
How can I modify the variable from within this function?
current_recordinnext_recordis local variable and it have nothing to do withcurrent_recordinlambda. If you assign new element tocurrent_recordinnext_recordyou lose contact with original record.current_record.some_variable = competitors[current_index + 1]andcurrent_record.index = current_index + 1.