-2
我忙於做一個學校任務,我已經停留在這段代碼,任何援助將不勝感激。 請參見下面的代碼:每個用戶的新列表條目
from tkinter import *
student_list = [['Tom','Information Systems'],['John','Computers'],['Johannes','Information Systems']]
class App(Frame):
def __init__(self,parent=None,**kw):
Frame.__init__(self,master=parent,**kw)
self.searchValue = StringVar()
self.searchBox = Entry(self,textvariable=self.searchValue)
self.searchBox.pack()
self.resultList = Listbox(self)
self.resultList.pack()
self.searchBox.bind('<Return>',self.update)
def update(self,e):
print("*")
self.resultList.delete(0,END)
searchkey = self.searchValue.get()
for student in student_list:
if searchkey == student[0]:
self.resultList.insert(END,str(student))
elif searchkey == student[1]:
self.resultList.insert(END,str(student))
if __name__ == '__main__':
root = Tk()
app = App(root)
app.pack()
root.mainloop()
是否有可能爲每個用戶創建條目或任何替代方法的新名單?
你有錯誤的縮進 - 代碼不起作用。 – furas
@furas你是說只有純粹的人才能運行Python嗎? –
@furas哦,凹痕。我讀了「意圖」。我的錯。 –