如何在wxPython中从父框架更新子面板的UI
我有一个主框架(wx.Frame),其中包含一个菜单栏和一个面板(wx.Panel)。该面板包含框架的主 UI。我想在单击菜单项时更新面板的用户界面。
我在与菜单项关联的事件处理程序中尝试 self.Refresh()、self.panel.UpdateWindowUI()、self.UpdateWindowsUI(wxUPDATE_UI_RECURSE) 但它们不起作用。我不想每次单击菜单项时都创建新面板并将它们添加回框架。
## =============== Event Handlers of the frame ===================
def OnOpenConfig(self, event):
"""Open the configuration file for the application"""
self.dir_name = os.getcwd()
dlg = wx.FileDialog(self, "Choose a file", self.dir_name, "", "*.conf", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.file_name = dlg.GetFilename()
self.dir_name = dlg.GetDirectory()
dlg.Destroy()
print os.path.join(self.dir_name, self.file_name)
# the sub panel is changed here because of the configuration file
self.panel.LoadConfigFile(os.path.join(self.dir_name, self.file_name))
# The update UI method should be here!!!!!!!
self.panel.Refresh()
I have a main frame (wx.Frame) containing a menu bar and a panel (wx.Panel). The panel contains the main UI of the frame. I would like to update the UI of the panel when clicking a menu item.
I was trying self.Refresh(), self.panel.UpdateWindowUI(), self.UpdateWindowsUI(wxUPDATE_UI_RECURSE) in the event handler associating to the menu item but they don't work. I don't want to create new panels and add them back to the frame every times I clicked the menu item.
## =============== Event Handlers of the frame ===================
def OnOpenConfig(self, event):
"""Open the configuration file for the application"""
self.dir_name = os.getcwd()
dlg = wx.FileDialog(self, "Choose a file", self.dir_name, "", "*.conf", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.file_name = dlg.GetFilename()
self.dir_name = dlg.GetDirectory()
dlg.Destroy()
print os.path.join(self.dir_name, self.file_name)
# the sub panel is changed here because of the configuration file
self.panel.LoadConfigFile(os.path.join(self.dir_name, self.file_name))
# The update UI method should be here!!!!!!!
self.panel.Refresh()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能解释一下 self.panel.LoadConfigFile 的作用吗?您也可以在刷新后尝试 self.panel.Update() 。
Could you give some explanation of what self.panel.LoadConfigFile does? You could also try self.panel.Update() after the Refresh.