簡體   English   中英

wxPython在運行時向ScrolledWindow添加/刪除控件

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

我正在嘗試在wxPython中ScrolledWindow添加/刪除多個項目。
目前我有以下控制架構: Imgur

我想將resultItem_panel多個實例添加到result_scrolledWindow
當我這樣做時,我首先必須手動縮放窗口,方法是用光標拖動窗口進行更新,然后使用result_scrolledWindow顯示滾動條。
我的代碼目前:

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

我在這做錯了什么?

更換:

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

有:

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

為我做了訣竅。
參考: 鳳凰城(wxPython)#1221

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM