尝试添加搜索功能来搜索该代码中的关键词:添加线性搜索
button1 = tk.Button(f1, text='Year 12, Paper One', command=lambda:raise_frame(f2)).pack()
button2 = tk.Button(f1, text='Year 12, Paper Two', command=lambda:raise_frame(f3)).pack()
button3 = tk.Button(f1, text='Year 13, Paper One', command=lambda:raise_frame(f4)).pack()
button4 = tk.Button(f1, text='Year 13, Paper Two', command=lambda:raise_frame(f5)).pack()
tk.Label(f2, text="Year 12, Paper One").pack()
tk.Button(f2, text="HOME", command=lambda:raise_frame(f1)).pack()
tk.Label(f3, text="Year 12, Paper Two").pack()
tk.Button(f3, text="HOME", command=lambda:raise_frame(f1)).pack()
tk.Label(f4, text="Year 13, Paper One").pack()
tk.Button(f4, text="HOME", command=lambda:raise_frame(f1)).pack()
tk.Label(f5, text="Year 13, Paper Two").pack()
tk.Button(f5, text="HOME", command=lambda:raise_frame(f1)).pack()
raise_frame(f1)
root.mainloop()
,这是我创建了当前搜索 - 这是正确的,我应该把这个代码?
def sequentialSearch(alist, item):
pos = 0
found = False
while pos < len(alist) and not found:
if alist[pos:pos+len(list(item))] == list(item):
found = True
else:
pos = pos+1
return found
不知道发生了什么事情与搜索。你想看看'item'是否在'alist'中?为什么不只是'如果项目在alist:退货'或什么的? – Matthias
所以即时添加每个按钮内的信息,我想要搜索一个词,用户从按钮的文本中输入 – jb23