简体   繁体   English

wxPython在运行时向ScrolledWindow添加/删除控件

[英]wxPython adding/removing controls during runtime to ScrolledWindow

I'm trying to add/remove multiple items to a ScrolledWindow in wxPython . 我正在尝试在wxPython中ScrolledWindow添加/删除多个项目。
At the moment I have the following control architecture: 目前我有以下控制架构: Imgur

I want to add multiple instances of the resultItem_panel to the result_scrolledWindow . 我想将resultItem_panel多个实例添加到result_scrolledWindow
When I do so I first have to scale the window manually by dragging it with the cursor for it to update and the result_scrolledWindow to show the scroll bars. 当我这样做时,我首先必须手动缩放窗口,方法是用光标拖动窗口进行更新,然后使用result_scrolledWindow显示滚动条。
My code at the moment: 我的代码目前:

def __addPublication(self, pub: Publication) -> None:
    resultItem_panel = ResultItemPanel(self, pub)

    # Add to parent sizer:
    self.result_sizer.Add(resultItem_panel, 0, wx.ALL, 5)
    self.Layout()
    self.Parent.Fit()

    # Store it so we later can Destroy() it again:
    self.resultItemPanels.append(resultItem_panel)

def clearPublications(self) -> None:
    for pub in self.resultItemPanels:
        pub.Destroy()
    self.resultItemPanels = []

    self.Layout()
    self.Parent.Fit()

What am I doing wrong here? 我在这做错了什么?

Replacing: 更换:

self.Layout()
self.Parent.Fit()

with: 有:

self.result_sizer.Layout()
self.PostSizeEvent()

did the trick for me. 为我做了诀窍。
Reference: Phoenix (wxPython) #1221 参考: 凤凰城(wxPython)#1221

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM