0

我想在我的第一个 python GUI 中复制列标题。我试过以下

    bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
    angle = wx.StaticText(panel,label="Angle")
    angle.SetFont(bfont)
    count_c = wx.StaticText(panel,label="Counts (C)")
    count_c.SetFont(bfont)
    count_u = wx.StaticText(panel,label="Counts (U)")
    count_u.SetFont(bfont)

    fgs.AddMany([(angle),(count_c), (count_u),
                 (angle),(count_c), (count_u)])


    vbox.Add(fgs, proportion=1,flag=wx.ALL|wx.EXPAND,border=5)

然而,这只显示了第二组标题。如何才能做到这一点?

4

1 回答 1

1

您不能将相同的小部件添加到两个不同的位置。相反,您必须为每一行创建单独的小部件。由于您希望每一行都具有相同的内容,因此可以使用循环:

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()
于 2013-07-25T18:10:42.360 回答