Hi,
I have a small wxpython program (see code below) that did not behave as I
expected. I am using wxwindows 2.3.3pre5.
__init__ in class MyFrame ends with twice the line
'panel.SetSizer(GetSizer1(panel))'.
I expected that the second line would make no difference, because in the
docs for wxwindow.setsizer I found that any prexisting sizer will be
deleted. So I thought that by executing the second line, the sizer would
simply be replaced by another sizer (with the same children).
This is not what happens, an extra wxTextCtrl is added in the left upper
corner.
So I would appreciate it if somebody could tell me what I am missing, and
how I can change the contents of a panel by giving it another sizer.
Thanks in advance.
from wxPython.wx import *
ID_FIELD1 = 20001
ID_TEXT1 = 20002
def GetSizer1(parent):
item0 = wxBoxSizer( wxVERTICAL )
item1 = wxFlexGridSizer( 0, 2, 0, 0 )
item2 = wxStaticText( parent, ID_FIELD1, "Field1", wxDefaultPosition,
wxDefaultSize, 0 )
item1.AddWindow( item2, 0, wxALIGN_CENTRE|wxALL, 5 )
item7 = wxTextCtrl( parent, ID_TEXT1, "", wxDefaultPosition,
wxSize(80,-1), 0 )
item1.AddWindow( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
item0.AddSizer( item1, 0, wxALIGN_CENTRE|wxALL, 5 )
return item0
class MyFrame(wxFrame):
def __init__(self, parent, id, title,
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
style = wxDEFAULT_FRAME_STYLE ):
wxFrame.__init__(self, parent, id, title, pos, size, style)
EVT_CLOSE(self, self.OnCloseWindow)
panel = wxPanel(self, -1)
panel.SetAutoLayout( true )
panel.SetSizer(GetSizer1(panel))
panel.SetSizer(GetSizer1(panel))
def OnCloseWindow(self, event):
self.Destroy()
class MyApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
frame = MyFrame(None, -1, "Test", wxPoint(50,50), wxSize(400,300) )
frame.Show(true)
return true
app = MyApp(1)
app.MainLoop()