用wxFormbuilder画了一个界面
现在想实现,点击add按钮,产生新的文本框控件
下面的代码产生的文本框控件会和之前的文本框重叠,请问要如何修改代码,才能让新增的文本框控件按照顺序排列。
import wx
class MyFrame1(wx.Frame):
def __init__(self, parent):
global bSizer2 ,fgSizer2
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
size=wx.Size(561, 430), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer2 = wx.BoxSizer(wx.VERTICAL)
fgSizer2 = wx.FlexGridSizer(0, 2, 0, 0)
fgSizer2.SetFlexibleDirection(wx.BOTH)
fgSizer2.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
self.m_textCtrl12 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_textCtrl12, 0, wx.ALL, 5)
self.m_button17 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_button17, 0, wx.ALL, 5)
self.m_textCtrl13 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_textCtrl13, 0, wx.ALL, 5)
self.m_button18 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_button18, 0, wx.ALL, 5)
self.m_textCtrl14 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_textCtrl14, 0, wx.ALL, 5)
self.m_button19 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_button19, 0, wx.ALL, 5)
self.m_textCtrl15 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_textCtrl15, 0, wx.ALL, 5)
self.m_button20 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_button20, 0, wx.ALL, 5)
bSizer2.Add(fgSizer2, 1, wx.EXPAND, 5)
self.m_button6 = wx.Button(self, wx.ID_ANY, u"add", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_button6, 0, wx.ALL, 5)
self.SetSizer(bSizer2)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.m_button6.Bind(wx.EVT_BUTTON, self.add_file)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def add_file(self, event):
event.Skip()
class MyProject_snMyFrame(MyFrame1):
def __init__(self, parent):
MyFrame1.__init__(self, parent)
def add_file(self, event):
# TODO: Implement add_file
# fgSizer2 = wx.FlexGridSizer(0, 2, 0, 0)
# fgSizer2.SetFlexibleDirection(wx.BOTH)
# fgSizer2.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
self.m_textCtrl4 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_textCtrl4, 0, wx.ALL, 5)
self.m_button30 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0)
fgSizer2.Add(self.m_button30, 0, wx.ALL, 5)
pass
if __name__ == '__main__':
app = wx.App()
frame = MyProject_snMyFrame(None)
frame.Show()
app.MainLoop()