我想在tkinter中创建20个输入框,每个输入框包含一个列表中的信息元素,我无法解决如何遍历每个输入框以显示列表中的新数据。该列表包含一个简单的字符串作为每个元素。我希望循环将result1更改为result(i),例如result1然后result2等等,以使其与文本框的名称匹配,并且每个文本框都具有字符串的下一个元素。
from tkinter import *
from tkinter.messagebox import *
def show_result():
input = str(search.get())
df_titles = pd.read_csv('movies.csv')
df_titles.drop('genres', axis=1, inplace=True)
df_titles['result'] = df_titles.astype(str).sum(axis=1).str.contains(input,case=False)
df_results = df_titles.loc[df_titles['result'] == True]
df_results.reset_index(drop=True)
list_1 = df_results['title'].tolist()
i = 0
for i in range(20):
result1.delete("0","end")
result1.insert(0,list_1[i])
main = Tk()
Label(main, text = "Search:").grid(row=0)
Label(main, text = "Results:").grid(row=1)
search = Entry(main)
result1 = Entry(main)
result2 = Entry(main)
result3 = Entry(main)
result4 = Entry(main)
result5 = Entry(main)
result6 = Entry(main)
result7 = Entry(main)
result8 = Entry(main)
result9 = Entry(main)
result10 = Entry(main)
result11 = Entry(main)
result12 = Entry(main)
result13 = Entry(main)
result14 = Entry(main)
result15 = Entry(main)
result16 = Entry(main)
result17 = Entry(main)
result18 = Entry(main)
result19 = Entry(main)
result20 = Entry(main)
search.grid(row=0, column=1)
result1.grid(row=1, column=1)
result2.grid(row=2, column=1)
result3.grid(row=3, column=1)
result4.grid(row=4, column=1)
result5.grid(row=5, column=1)
result6.grid(row=6, column=1)
result7.grid(row=7, column=1)
result8.grid(row=8, column=1)
result9.grid(row=9, column=1)
result10.grid(row=10, column=1)
result11.grid(row=11, column=1)
result12.grid(row=12, column=1)
result13.grid(row=13, column=1)
result14.grid(row=14, column=1)
result15.grid(row=15, column=1)
result16.grid(row=16, column=1)
result17.grid(row=17, column=1)
result18.grid(row=18, column=1)
result19.grid(row=19, column=1)
result20.grid(row=20, column=1)
Button(main, text='Quit', command=main.destroy).grid(row=21, column=0, sticky=W, pady=4)
Button(main, text='Show', command=show_result).grid(row=21, column=1, sticky=W, pady=4)
mainloop()
这是你想要的?
main = Tk()
Label(main, text = "Search:").grid(row=0)
search = Entry(main)
search.grid(row=0, column=1)
for i in range(1,21):
Label(main, text = "Result {}:".format(i)).grid(row=i)
Entry(main).grid(row=i, column=1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句