我在更新界面时遇到问题,(简化)代码如下:
##here: two nested for loops
f = Frame(master,height=600,width=200, bd=1, relief=SUNKEN)
f.grid(row=rowN, column=colN, pady=15, padx= 0)
Label(f, text="Mesa: " + str(lOfKeys[count])).pack(side = TOP)
scrollbar = Scrollbar(f, orient=VERTICAL)
listbox = Listbox(f, yscrollcommand=scrollbar.set, width=19, bg="white")
listboxFrames[listbox] = f
tableRel[listbox] = lOfKeys[count]
scrollbar.config(command=listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.pack(side=TOP)
listbox.bind("<Double-Button-1>", hideOrder)
listbox.bind("<Return>", hideOrder)
index = 0
listbox.delete(0, END)
##for loop to fill the listbox
if len(listbox.get(0, END)) == 0:
print "forget" + str(lOfKeys[count])
f.grid_forget()
count += 1
当我重新启动程序时,上面的解决方案似乎工作正常,但是如果代码被master.after
调用,则它不会使框架消失,相反,它实际上会复制它,有时表现得很陌生。
我想知道什么是最好的方法,因为列表框经常被填满和清空。