If the sizer has children, then GetChildren does return a list of widgets. I've done it many times with wxPython 2.8. I don't remember anyone mentioning it was different in 2.9 or Phoenix, so I'm guessing it's not. Can you tell us which OS and wxPython version you're using?
If you want to know how to get an arbitrary sizer, you might try GetContainingSizer or use the Widget Inspection Tool
EDIT (08/22/2012): Here's a working example:
import wx
########################################################################
class MyApp(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Example")
panel = wx.Panel(self)
lbl = wx.StaticText(panel, label="I'm a label!")
txt = wx.TextCtrl(panel, value="blah blah")
btn = wx.Button(panel, label="Clear")
btn.Bind(wx.EVT_BUTTON, self.onClear)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(lbl, 0, wx.ALL, 5)
self.sizer.Add(txt, 0, wx.ALL, 5)
self.sizer.Add(btn, 0, wx.ALL, 5)
panel.SetSizer(self.sizer)
#----------------------------------------------------------------------
def onClear(self, event):
""""""
children = self.sizer.GetChildren()
for child in children:
widget = child.GetWindow()
print widget
if isinstance(widget, wx.TextCtrl):
widget.Clear()
if __name__ == "__main__":
app = wx.App(False)
frame = MyApp()
frame.Show()
app.MainLoop()
SetSizer()
. Normally, you only callSetSizer()
on awx.Frame
orwx.Panel
.GetChildren()
from sizer, but it just return SizerItemList not actual widget list, so I think I can useGetSizer()
in all widgets to return the sizer, of course it return nothing. Sorry, not make myself clear.