简体   繁体   中英

wxPython adding/removing controls during runtime to ScrolledWindow

I'm trying to add/remove multiple items to a ScrolledWindow in wxPython .
At the moment I have the following control architecture: Imgur

I want to add multiple instances of the resultItem_panel to the 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.
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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