通过for循环WXpython将面板添加到GridSizer

时间:2018-10-03 14:14:59

标签: python python-3.x debugging wxpython wxpython-phoenix

我一直在这个问题上停留,我觉得这很愚蠢。我有3个清单。 list1包含所有要添加到我的网格化器的面板。 list2包含我的3x3网格化器的列表。我试图将这些面板从列表一添加到尺寸调整器中,一旦达到9,则将其放置在下一个网格化器中。以下是我的代码和我不断收到的错误

listOfWaferPanels = []
listOfGridSizers = []
listOfPanels = []
for lotID, wafNum in df3.groupby(['LOT_WF']):
        df4 = wafNum[['X_COORD', 'Y_COORD', 'HB_NUM']]
        print(wafNum)
        print("\n")
        my_list = df4.transform(tuple, axis=1).tolist()
        self.temp_panels = wm_core.WaferMapPanel(self, my_list, waferDesign, data_type='discrete'.lower())
        listOfWaferPanels.append(self.temp_panels)
        waferNum += 1
numOfTabs = (waferNum//9) + 1
    for tab in range(numOfTabs):
        tabString = ("Page"+ str(tabNumber))
        tempGridSizers = wx.GridSizer(3,3,0,0)
        tempPanel = wx.Panel(self.waferTab,wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        tabNumber += 1
        listOfGridSizers.append(tempGridSizers)
        listOfPanels.append(tempPanel)
for tab in range(numOfTabs):
        for i in range(waferNum):
            listOfGridSizers[i//9].Add(listOfWaferPanels[i], 1 , wx.EXPAND)
        listOfPanels[tab].SetSizer(listOfGridSizers[tab])
        self.waferTab.AddPage(listOfPanels[tab], "tab", select=False)

并且错误在

以下
listOfGridSizers[i//9].Add(listOfWaferPanels[i], 1 , wx.EXPAND)wx._core.wxAssertionError: C++ assertion "!sizer || m_containingSizer != sizer" failed at ..\..\src\common\wincmn.cpp(2470) in wxWindowBase::SetContainingSizer(): Adding a window to the same sizer twice?

1 个答案:

答案 0 :(得分:0)

抱歉,这很愚蠢。如果有人遇到同一问题,那是我做错了。 我将面板添加到gridsizer中,但是效果很好,但是问题再次出现在外部循环时,因为这意味着我要再次将面板添加到gridsizer中!实际上解释了错误代码。我只是将嵌套的for循环分成2个单独的循环,就可以了