我如何从列表(每个索引独立) - 在字典中 - 写入条目列表?
How do I write from a list (each index independently) - within a dictionary - to a list of Entries?
我正在根据用户输入的整数设置多个输入字段和跟踪变量。然后将条目信息存储到字典中的列表中。
存在两个按钮:'enable',它允许编辑输入字段,但同时从字典中获取信息并将其显示在输入字段中。
'disable' 按钮清除输入字段并禁用编辑。还更新字典。
问题是将每个单独的条目读回条目字段,字典如下所示:
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
我不能选择'F'的单个值,并在选择'enable'时在各个入口字段中显示。
我知道如何访问 '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("")
禁用选项执行其确切功能:初始化 'F'、重新读取条目、将其存储在 dict_test 中并禁用条目。
然而,'enable' 在尝试遍历 'F'
时显示 'index out of bounds' 错误
for j in range(len(dict_test['A'][3]['F'])):
sv[j].set(dict_test['A'][3]['F'][j])
我正在根据用户输入的整数设置多个输入字段和跟踪变量。然后将条目信息存储到字典中的列表中。 存在两个按钮:'enable',它允许编辑输入字段,但同时从字典中获取信息并将其显示在输入字段中。 'disable' 按钮清除输入字段并禁用编辑。还更新字典。 问题是将每个单独的条目读回条目字段,字典如下所示:
dict_test = {'A': ['B', [1, 1], True, {'E': '', 'F': [], 'G': []}]}
我不能选择'F'的单个值,并在选择'enable'时在各个入口字段中显示。
我知道如何访问 '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("")
禁用选项执行其确切功能:初始化 'F'、重新读取条目、将其存储在 dict_test 中并禁用条目。 然而,'enable' 在尝试遍历 'F'
时显示 'index out of bounds' 错误for j in range(len(dict_test['A'][3]['F'])):
sv[j].set(dict_test['A'][3]['F'][j])