pythonpopulatewxwidgetswxformbuilder

Populate wxChoice at Start of Program Run | Python


As soon as my program is run, I want my wxChoice to be populated with items from a list I designate. I am using wxFormBuilder to handle the GUI elements of my program.

My code:

    def onDropDownSelection(self, parent):

    #Open designated file 
    lines = tuple(open("/Users/it/Desktop/Classbook/masterClassList.txt", 'r'))

    #Strips the first line of the file, splits the elements, assigns to "one"
    lines[1].rstrip()
    one = lines[1].split("|")

    #My attempt to populate the wxChoice with my list "one"
    self.firstChoice.SetItems(one)

This event is activated when the user clicks on the drop-down (wxChoice) menu, and re-populates every time it is clicked on.

Is there a way I can populate my wxChoice, only once, upon the initial opening/running of the program?

I have placed this code where the wxChoice is being created. However, I am now experiencing a "Unindent does not match any outer indentation level" on line 44. How do I fix this?

enter image description here


Solution

  • Check for your indentation. Some times if you copy paste, this can mess things up. Just rewrite it or replace it with another statement. See here: IndentationError: unindent does not match any outer indentation level

    Problem is if you make your indentation with tabs and then copy-paste some code from an example page, where the indentation is made with spaces. Then you have mixed Indentations. I've had these a lot of times.