0

I've got a Listbox that isn't updating after inserting, which is in the update_listbox function. I've put a couple of print statements in to check list size before and after update, and another print to check values being inserted. All the print statements show what I would expect if it was working. But it isn't showing it in 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)))

EDIT

As suggested by Mr steak I changed Listbox(self, selectmode=SINGLE) to Listbox(master, selectmode=SINGLE) but that created two listboxes one above and below the Entryframe (added code below) and the one below correctly displayed the update. Why am I seeing two listboxes now?

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)
martineau
  • 119,623
  • 25
  • 170
  • 301
tchadwik
  • 1,429
  • 2
  • 10
  • 13
  • Now that I see your full code, can it be that `products.get_item(i)` just returns an empty string? Maybe there are items in the listbox, but they contain just empty strings? – sloth Oct 10 '12 at 06:59
  • I thought of that and so i added a print statement of str(products.get_item(i) and it was printin the correct value. – tchadwik Oct 10 '12 at 07:00
  • products is an instance from the class Product, which is basicly a dictionary that has bunch of functions to manipulate the dictionary. I hope that it explains it clearly. I've defined it as products = Product(). – tchadwik Oct 10 '12 at 07:10
  • If i replace str(products.get_item(i) with some string, it works fine. – tchadwik Oct 10 '12 at 07:12
  • Maybe the `get_item` method is wrong? – sloth Oct 10 '12 at 07:13
  • `get_item` return statement is `return self._products.get(itemID)` where self._products is the refering to the dictionary and itemID is the key. What is confusing me is that the print statement of `get_item` is giving me the correct value. – tchadwik Oct 10 '12 at 07:23
  • What type are the values in the dictionary? – sloth Oct 10 '12 at 07:33
  • The value types in the dictionary are strings. I put a couple of print statements just before the insert and this is what i got `print products.get_item(i)` gives me correct output `print str(products.get_item(i))` also gives me correct output `print type(str(products.get_item(i)))` gives me string type `print type(products.get_item(i))` gives me – tchadwik Oct 10 '12 at 07:49
  • After trying different things. I found that if I called main after I've populated my products dictionary it works properly. Where main just does `root = tk()` etc. And my products dictionary is populated by opening a txt file. – tchadwik Oct 10 '12 at 08:09

0 Answers0