Tom McDonald
Tom McDonald

Reputation: 269

wxComboBox list of lists issue

I am having an issue using a list of lists with the wxComboBox for wxPython.

Using the following list of lists:

    aps = [['AP0','AP1','AP2','AP3','AP4'],
           ['AP2'],
           ['AP1'],
           ['AP1','AP2','AP3'],
           ['AP1'],
           ['AP1','AP2'],
           ['AP1'],
           ['AP1'],
           ['AP1'],
           ['AP1'],
           ['AP1','AP2','AP3'],
           ['AP1_N','AP2_E','AP3_S','AP4_W'],
           ['AP1','AP2','AP3']]

    apOps = aps[11][3]
    print apOps

    self.apInput = wx.ComboBox(panel1, -1, choices = apOps)

Using this example print command outputs "AP4_W' as expected. However the ComboBox splits each character as an item in its list of choices.

If I just use one item from a list such as

apOps = aps[0]

I get the entire first list as options as expected and wanted. I can also get other one item lists to appear correctly such as

apOps = aps[1]

Correctly prints and shows in the ComboBox as "AP2"

I'm not sure if there is a different way I should be calling the items for the ComboBox or what exactly I'm doing wrong.

As always the help is much appreciated!

Upvotes: 0

Views: 47

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33111

wxPython is taking your string and turning it into a list. You can do the same thing yourself by doing this:

print list(apOps)

If you don't want that to happen, then you should change the code where you create the wx.ComboBox to look like this:

self.apInput = wx.ComboBox(self, choices=[apOps])

This will create a one item list that just contains the string. If you want the string to also be the default choice, you can do this:

self.apInput = wx.ComboBox(self, value=apOps, choices=[apOps])

Hope that helps!

Upvotes: 1

Related Questions