如何强制刷新 wx.Panel?
我正在尝试修改面板的控件,更新它,然后继续执行代码。 问题似乎是面板在刷新之前正在等待空闲。 我当然尝试过刷新以及 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有一个
StaticBitmap
,同样,它不会通过任何这些技术进行更新(包括接受的答案中建议的Update
)。我发现在
Panel
上调用.Hide()
和.Show()
足以刷新图像。 我怀疑如果我针对较低级别的对象(例如StaticBitmap
)运行这些函数,也会出现同样的情况。I had a
StaticBitmap
that, similarly, wouldn't update by any of these techniques (including theUpdate
suggested in the accepted answer).I found that calling
.Hide()
and.Show()
on thePanel
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 theStaticBitmap
.您可以将面板的可变部分放在子面板上,例如这样:
You could put the mutable part of your panel on subpanels, e.g. like this:
要更新 Frame 中的 UI 更改,请使用以下命令
To update UI changes in Frame use following command
您需要调用 <代码>更新方法。
You need to call the
Update
method.