Search code examples
pythonpython-3.xwxpythonwxwidgets

WxPython converting choice to number value TypeError


So I imagine this is a fairly simple question where I just don't understand the error. This is my current code:

        # SINGLE CHOICE INPUT
        choices = ["Auto", "Manual", "Manual (code only)"]
        chooseOneBox = wx.SingleChoiceDialog(None, "Setup / Opsætning", "Setup / Opsætning", choices)

        if chooseOneBox.ShowModal() == wx.ID_OK:
            setupChoice = choices.index[chooseOneBox.GetStringSelection()] + 1
            if setupChoice == 1:
                print(choices[setupChoice]-1)
            elif setupChoice == 2:
                print(choices[setupChoice]-1)
            print(choices[setupChoice])

So I have the list choices which contains a bunch of options which are being correctly displayed in chooseOneBox. When trying to do:
setupChoice = choices.index[chooseOneBox.GetStringSelection()] + 1 I get the following error: 'builtin_function_or_method' object is not subscriptable.

I want to convert the string from chooseOneBox to an integer for simplistic reasons. How do I avoid getting that error?


Solution

  • index is a function of the list that returns the first index of occurrence of an item.

    Replace

    choices.index[chooseOneBox.GetStringSelection()] + 1
    

    With this

    choices.index(chooseOneBox.GetStringSelection()) + 1