如何强制刷新 wx.Panel?

发布于 2024-07-29 15:58:20 字数 783 浏览 7 评论 0原文

我正在尝试修改面板的控件,更新它,然后继续执行代码。 问题似乎是面板在刷新之前正在等待空闲。 我当然尝试过刷新以及 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()

还有其他人遇到过类似的情况吗? 如果是的话你是如何解决的?

I am trying to modify the controls of a Panel, have it update, then continue on with code execution. The problem seems to be that the Panel is waiting for Idle before it will refresh itself. I've tried refresh of course as well as GetSizer().Layout() and even sent a resize event to the frame using the SendSizeEvent() method, but to no avail. I'm at a loss here, I find it difficult to believe there is no way to force a redrawing of this panel. Here is the code that changes the controls:

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

Has anybody else encountered anything like this? And how did you resolve it if so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

看透却不说透 2024-08-05 15:58:21

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

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

I had a StaticBitmap that, similarly, wouldn't update by any of these techniques (including the Update suggested in the accepted answer).

I found that calling .Hide() and .Show() on the Panel was enough to refresh the image. I suspect that the same would be true if I had run the functions against a lower-level object like the StaticBitmap.

ㄖ落Θ余辉 2024-08-05 15:58:21

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

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

You could put the mutable part of your panel on subpanels, e.g. like this:

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()
青春如此纠结 2024-08-05 15:58:21

要更新 Frame 中的 UI 更改,请使用以下命令

self.Layout()
self.Update()

To update UI changes in Frame use following command

self.Layout()
self.Update()
另类 2024-08-05 15:58:20

您需要调用 <代码>更新方法。

You need to call the Update method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文