wxpython可折叠窗格不一致的大小响应

问题描述 投票:1回答:1

好吧,有些奇怪,我无法弄清楚。假设我有一些类别,每个类别都有一些项目,都都符合字典。

import wx
nyoom = {}
nyoom['spiders'] = ['Yellow Sac', 'Orbweaver', 'Garden']
nyoom['cats']= ['Bombay','Angora']
nyoom['cambrian'] = ['Wiwaxia','Hallucigenia','Pikaia','Alomancaris']

然后我想将每个类别显示为一个按钮,该按钮也会折叠或显示该类别的所有内容作为按钮。

class SeqFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__( self, None, wx.ID_ANY, "GUI Woes", size=(400,400))
        self.panel = wx.Panel(self, wx.ID_ANY)
        sizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5) #sizer for the window
        numActsTxtBox = wx.TextCtrl( self.panel, -1, "1", size=(40, -1))
        numActsTxtTxt = wx.CheckBox( self.panel, -1, "Number of Times")
        sizer.Add( numActsTxtTxt, 0, wx.ALL )
        sizer.Add( numActsTxtBox, 0, wx.ALL )
        for categories in nyoom.keys():
            self.categPanes=[]
            self.categPanes.append(wx.CollapsiblePane(self.panel, -1, label=categories))
            self.buildPanes(self.categPanes[-1], sizer)
            thisPanel = self.categPanes[-1].GetPane()
            panelSizer = wx.BoxSizer( wx.VERTICAL ) #sizer for the panel contents
            sortedCategory = nyoom[categories]
            sortedCategory.sort()
            for i in range(0,len(nyoom[categories])): 
                thisSeq = wx.Button( thisPanel, label=sortedCategory[i], name=sortedCategory[i])
                panelSizer.Add( thisSeq, 0, wx.GROW | wx.ALL ,0 )
        thisPanel.SetSizer(panelSizer)
        panelSizer.SetSizeHints(thisPanel)
        self.panel.SetSizerAndFit(sizer)
        self.Fit()
    def buildPanes(self, categPane, sizer):
        categPane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged)
        sizer.Add(categPane, 0, wx.GROW | wx.ALL, 0)
    def OnPaneChanged(self, evt):
        self.panel.GetSizer().Layout()
        self.panel.Fit()
        self.Fit()

if __name__ == '__main__': 
    app = wx.App()
    frame = SeqFrame()
    frame.Show(True)
    app.MainLoop() 

(这是我的整个示例应用程序。)我无法弄清楚为什么,但一切都适用于字典中的最后一个类别:但以前的类别只能显示一个按钮/项目。

python wxpython wxwidgets sizer wxgrid
1个回答
1
投票

thisPanel正在你的循环中设置,但是你在循环之后调用SetSizer,所以只有最后一个thisPanel得到一个sizer。将调用移动到循环内的SetSizer

© www.soinside.com 2019 - 2024. All rights reserved.