Adding / Removing Controls from a wxPython Frame

I have a mini-Frame whose child controls change based on a user selection. It took awhile to get the resizing and layout working as controls are added and removed from the panel. This is the final code that works. The event handler calls selectedXXX, where XXX is one of the options. Each set of controls that are shown or hiddern reside in their own sizer, although if it were just one control you can show or hide it directly.

<pre>
def selectedXXX(self):
&nbsp;&nbsp;self.mainSizer.Show(self.rXXXSizer)
&nbsp;&nbsp;self.mainSizer.Hide(self.ZZZSizer)
&nbsp;&nbsp;#hide other sizers/windows as needed
&nbsp;&nbsp;.
&nbsp;&nbsp;.
&nbsp;&nbsp;.
&nbsp;&nbsp;self.updateAfterControlsChange()
<br>
def updateAfterControlsChange(self):
&nbsp;&nbsp;self.Fit()
&nbsp;&nbsp;self.GetParent().Fit()
&nbsp;&nbsp;self.GetParent().SendSizeEvent()
</pre>

This entry was posted in Python, wxPython. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *