Alex,May I recommend actually reading about the basic Python data types before attempting to create even simple applications? In particular, you should be aware that a dictionary is an inherently unordered type, as the underlying datastructure, namely a hash table, is unordered. The point of such a structure is for associating a key with a value. If you need to preserve ordering, either use an ordered dict (a Python 2.7+ feature), or perhaps an alist-like sequence of tuples. You can also pull the keys out of a dictionary and sort them for use in a list box, something akin to lb = wx.ListBox(parent=self, value=sorted(some_dict)) #Note that this is taking advantage of the fact that iterating dicts gives their keys. But in all seriousness, please do go study the basics before hitting the list with a question like this.
Q On 6/18/2011 9:17 PM, Alex Hall wrote:
Hi all, When I use a ListBox, I see that I can give it a names list and a values list. I understand that names are what is shown to the user, but what do values do? They do not seem to be used in the AddListBox method at all. A second question goes along with this: when I pass a list to be the names list in a ListBox, all is well. When I pass a dictionary, though, all my items suddenly get out of order. For example, if I pass ["apple", "banana", "orange"] as the names list in the AddListBox method, the items appear in that order. When I instead do this: items={ "apples":"red", "bananas":"yellow", "oranges":"orange" } and then add to my dialog: dlg.AddListBox(label="fruit", names=items.keys()) I get a list with the three fruits out of order, appearing as "apples, oranges, bananas" in the list instead. I imagine this is a python problem in the keys() method of the dictionary, but I cannot imagine why it would do it at all. How do I get around it so that items appear in the same order as they do in my dictionary? Thanks!
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind