Tkinter列表框未更新

时间:2012-10-10 06:27:58

标签: python tkinter

插入后我有一个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)

0 个答案:

没有答案
相关问题