gpt4 book ai didi

python - wxpython 可折叠 Pane 大小响应不一致

转载 作者:行者123 更新时间:2023-12-01 09:34:28 29 4
gpt4 key购买 nike

好吧,有些事情很奇怪,我无法弄清楚。假设我有一些类别,每个类别都有一些项目,全部放入字典中。

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()

(这是我的整个示例应用程序。)我不明白为什么,但对于字典中的最后一个类别来说一切正常: screenshot但前面的类别只能显示一个按钮/项目。
screenshot 2

最佳答案

thisPanel 正在循环内设置,但您在循环后调用 SetSizer,因此只有最后一个 thisPanel 获得了 sizer 。将调用移至循环内的 SetSizer

关于python - wxpython 可折叠 Pane 大小响应不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49661746/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com