我使用 Tkinter 创建了一个弹出式窗口,可以显示列表中的所有单词。我使用了for循环,这样我就可以将所有的单词插入到我设置的Listbox中。出现的问题是,for循环把列表中的单词反过来,每个索引插入一个字母。我希望每一个索引都有一个单词以不颠倒的顺序插入。
编码
for words in list:
index = 0
if words != 0:
index += 1
listbox.insert(index, words)
首先,你应该避免使用关键字 list
作为变量。 例如,将其改为: wordlist
代替。 另外,你应该在列表框的末尾插入单词,而不是用 index
:
for word in wordlist: # better rename list to wordlist
listbox.insert('end', word) # insert at the end of listbox instead