0

我有一个Listbox在插入后没有更新的函数,它在update_listbox函数中。我print在更新前后添加了一些语句来检查列表大小,并使用另一个打印来检查插入的值。所有的print陈述都显示了我对它的期望。但它没有显示在Listbox.

class View(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.list = Listbox(self, selectmode=SINGLE)
        self.list.pack(fill=BOTH, expand=YES)
        self.list.delete(0, END)
        print(self.list.size()) #shows 0 which
        self.update_listbox()
        print(self.list.size()) #shows the correct number, but listbox doesn't show anything

    def update_listbox(self):
        temp=products.get_keys()
        self.list.delete(0, END)
        for i in temp:
            print str(products.get_item(i)) #Is showing the correct output.
            self.list.insert(END, str(products.get_item(i)))

编辑

正如牛排先生所建议的那样,我改为Listbox(self, selectmode=SINGLE)Listbox(master, selectmode=SINGLE) 创建了两个列表框,一个在Entryframe(下面添加的代码)的上方和下方,下面的一个正确显示了更新。为什么我现在看到两个列表框?

class Controller(object):
    def __init__(self, master=None):
        self._master = master
        #filemenubar
        self.menu()
        #listbox
        self.listboxFrame = View(master)
        self.listboxFrame.pack(fill=BOTH, expand=YES)
        #entry widget
        self.EntryFrame = Other(master)
        self.EntryFrame.pack(fill = X)
4

0 回答 0