您不能将相同的小部件添加到两个不同的位置。相反,您必须为每一行创建单独的小部件。由于您希望每一行都具有相同的内容,因此可以使用循环:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
vbox = wx.BoxSizer(wx.VERTICAL)
fgs = wx.FlexGridSizer(rows=2, cols=3, vgap=5, hgap=5)
# add two rows of widgets to the sizer
widgets = []
for i in range(2):
angle = wx.StaticText(self,label="Angle")
angle.SetFont(bfont)
widgets.append(angle)
count_c = wx.StaticText(self,label="Counts (C)")
count_c.SetFont(bfont)
widgets.append(count_c)
count_u = wx.StaticText(self,label="Counts (U)")
count_u.SetFont(bfont)
widgets.append(count_u)
fgs.AddMany(widgets)
vbox.Add(fgs, proportion=1,flag=wx.ALL|wx.EXPAND,border=5)
self.SetSizer(vbox)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()