That's actually pretty easy. Here's one way to do it:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.txtSizer = wx.BoxSizer(wx.VERTICAL)
txt = wx.TextCtrl(self)
self.txtSizer.Add(txt, 0, wx.EXPAND|wx.ALL, 5)
self.mainSizer.Add(self.txtSizer, 0, wx.EXPAND, 5)
add_btn = wx.Button(self, label="Add")
add_btn.Bind(wx.EVT_BUTTON, self.onAdd)
process_btn = wx.Button(self, label="Process")
process_btn.Bind(wx.EVT_BUTTON, self.onProcess)
self.mainSizer.Add(add_btn, 0, wx.ALL, 5)
self.mainSizer.Add(process_btn, 0, wx.ALL, 5)
self.SetSizer(self.mainSizer)
#----------------------------------------------------------------------
def onAdd(self, event):
""""""
self.txtSizer.Add(wx.TextCtrl(self), 0, wx.EXPAND|wx.ALL, 5)
self.mainSizer.Layout()
#----------------------------------------------------------------------
def onProcess(self, event):
""""""
children = self.txtSizer.GetChildren()
for child in children:
widget = child.GetWindow()
if isinstance(widget, wx.TextCtrl):
print widget.GetValue()
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Dynamic")
panel = MyPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
As a bonus, I also show how to get the information out of the text controls too. Note that the tab order gets screwed up when you add a text control.