为了清楚克雷默的破坏评论,这是我解决我遇到的问题的方法:
class myFrame(wx.Frame):
def__init__(self, title):
#make the FlexGridSizer specifying only the columns, not the rows
#make a panel
#create widgets with the panel as the parent
#add widgets to the sizer
self.addLastRow()
#set the sizer, call layout, etc...
def addLastRow(self):
lastBtn = wx.Button(self.myScrolledPanel, -1,"Add New Row", style=wx.BU_EXACTFIT)
numBlanks = self.numTotalColumns-1
for i in range(numBlanks):
self.myFlexGridSizer.AddF(wx.StaticText(self.myScrolledPanel, -1, ''), wx.SizerFlags(0))
self.myFlexGridSizer.AddF(lastBtn, wx.SizerFlags(0))
self.Bind(wx.EVT_BUTTON, self.AddNewRowElements, addButton)
def removeLastRow(self):
myFlexGridItems = self.myFlexGridSizer.GetChildren()
for i in range(self.numTotalColumns):
myFlexGridItems[len(myFlexGridItems)-1].GetWindow().Destroy()
def AddNewRowElements(self, event):
self.removeLastRow()
#add elements
self.addLastRow()
self.myFlexGridSizer.Layout()