【问题标题】:How do you force refresh of a wx.Panel?你如何强制刷新 wx.Panel?
【发布时间】:2010-11-16 20:50:21
【问题描述】:

我正在尝试修改面板的控件,使其更新,然后继续执行代码。问题似乎是面板在刷新之前等待空闲。我当然尝试过刷新以及 GetSizer().Layout(),甚至使用 SendSizeEvent() 方法向框架发送了调整大小事件,但无济于事。我在这里不知所措,我很难相信没有办法强制重绘这个面板。这是更改控件的代码:

def HideButtons(self):
        self.newButton.Show(False)
        self.openButton.Show(False)
        self.exitButton.Show(False)
        self.buttonSizer.Detach(self.newButton)
        self.buttonSizer.Detach(self.openButton)
        self.buttonSizer.Detach(self.exitButton)
        loadingLabel = wx.StaticText(self.splashImage, wx.ID_ANY, "Loading...", style=wx.ALIGN_LEFT)
        loadingLabel.SetBackgroundColour(wx.WHITE)
        self.buttonSizer.Add(loadingLabel)
        self.GetSizer().Layout()
        self.splashImage.Refresh()

有没有其他人遇到过这样的事情?如果是这样,您是如何解决的?

【问题讨论】:

  • 你试过self.Show()吗?

标签: python wxpython refresh panel


【解决方案1】:

你需要调用Update方法。

【讨论】:

  • Update () 单独对我没有帮助(StaticBitmaps 在 GridSizerPanel),但文档说 Refresh () 会触发无条件重绘 - 它之后是Update ()
  • Phoenix 更改了文档链接结构。 Updatehas moved。这正是我正在寻找的。谢谢!
【解决方案2】:

我有一个StaticBitmap,同样,它不会通过任何这些技术进行更新(包括接受的答案中建议的Update)。

我发现在Panel 上调用.Hide().Show() 足以刷新图像。我怀疑如果我对像StaticBitmap 这样的较低级别对象运行函数,情况也会如此。

【讨论】:

    【解决方案3】:

    您可以将面板的可变部分放在子面板上,例如像这样:

    def MakeButtonPanels(self):
        self.buttonPanel1 = wx.Panel(self)
        self.Add(self.buttonPanel1, 0, wxALL|wxALIGN_LEFT, 5)
        # ... make the three buttons and the button sizer on buttonPanel1
    
        self.buttonPanel2 = wx.Panel(self)
        self.Add(self.buttonPanel2, 0, wxALL|wxALIGN_LEFT, 5)
        # ... make the loading label and its sizer on buttonPanel2
    
        self.buttonPanel2.Show(False) # hide it by default
    
    def HideButtons(self):
        self.buttonPanel1.Show(False)
        self.buttonPanel2.Show(True)
        self.Layout()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多