【问题标题】:wxpython collapsible panes inconsistent sizing responsewxpython 可折叠窗格大小不一致的响应
【发布时间】:2018-09-14 15:35:12
【问题描述】:

好吧,有些奇怪,我想不通。假设我有一些类别,每个类别都有一些项目,都适合字典。

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】:

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

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      相关资源
      最近更新 更多