I am setting up a number of Entry fields and trace-variables based on a user inputted integer. The entry information is then store to a list in dictionary. Two buttons exist: 'enable', which enables the entry-fields for editing but at the same time, fetches the information from the dictionary and displays it on the entry field. 'disable' button clears the entry fields and disables editing. Also updates the dictionary. The problem is reading each individual entry back into the entry fields with the dictionary looking like this:
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
I cannot take the individual values of 'F' and display it on the respective entry field when 'enable' is selected.
I know how to access the whole list of 'F' (dict_test['A'][3]['F'])
# User input:
phases = 3
# The Dictionary to which the trace-variables are stored
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
headings = ["FRa"]
sv = [StringVar() for i in range(phases)] # Holds the Entry inputs
fra_list = []
# The Entry-fields
fra_entries = [Entry(frame, width=10, state=DISABLED, justify=RIGHT, textvariable=sv[i]) for i in range(phases)]
...
enable_button = Button(root, text="Enable", command=lambda: enable())
disable_button = Button(root, text="Disable", command=lambda: disable())
...
def enable():
for i in range(len(fra_entries)):
fra_entries[i].config(state=NORMAL)
sv[i].set(dict_test['A'][3]['F'][i]) # Causes the problem !!!!
def disable():
dict_test['A'][3]['F'] = []
fra_list = []
for i in range(phases):
fra_list.append(sv[i].get())
dict_test['A'][3]['F'].append(fra_list[i])
for i in range(len(fra_entries)):
fra_entries[i].config(state=DISABLED)
sv[i].set("")
The disabled option does its exact function: initializes 'F', re-reads the entries, stores it in dict_test and disables the entries. 'enable', however, shows an 'index out of bounds' error when trying to loop through 'F'