title: Clearing wxPython frame on a button click
body: <p>Using wxPython 2.8 on Arch (works fine, but I don't think it should...) and wxPython 2.9 on Mac OS X, both Python 2.7. My code consists of switching between different screens depending on the current states. On each switch between a state (screen) I clear my main Sizer and call DestroyChildren() on my main frame, then I populate them with other components.</p>
  
  <p>So essentially I think I have outside threads trying to change wx components in the main thread. I'm guessing this is not best practise in wxPython, so how would I be able to amend this?</p>
  
  <p>Attaching event to a button </p>
  
  <pre><code>self.login_button.Bind(wx.EVT_BUTTON, self.login_button_click)
  </code></pre>
  
  <p>The log in event does stuff and calls an update (the model state is changed here)</p>
  
  <pre><code>def login_button_click(self,event):
  
      ...
      # CHANGE THE self.model.current_state
      ...
  
      self.update(None)
  </code></pre>
  
  <p>The update clears the frame, checks state and calls a builder method</p>
  
  <pre><code>def update(self, o):
      self.box.Clear() #clear the main sizer
      self.frame.DestroyChildren() #delete all children, THIS IS WHERE THE CODE SEGFAULTS
  
  
      print "STATE: "+self.model.current_state
  
      if self.model.current_state == self.model....
          ...
      elif self.model.current_state == self.model....
          ...
  </code></pre>
  
  <p>I have tried using wx.CallAfter, which resulted in all of the components beign removed at the end of the event, even the newly built ones.</p>