如何从wxPython中的父帧更新子面板的UI

如何从wxPython中的父帧更新子面板的UI,wxpython,Wxpython,我有一个主框架wx.frame,包含一个菜单栏和一个面板wx.panel。该面板包含框架的主UI。我想在单击菜单项时更新面板的UI 我在与菜单项关联的事件处理程序中尝试self.Refresh、self.panel.UpdateWindowUI、self.updatewindowuiwxUpdate\u UI\u递归,但它们不起作用。我不想每次单击菜单项时都创建新面板并将其添加回框架 ## =============== Event Handlers of the frame =========

我有一个主框架wx.frame,包含一个菜单栏和一个面板wx.panel。该面板包含框架的主UI。我想在单击菜单项时更新面板的UI

我在与菜单项关联的事件处理程序中尝试self.Refresh、self.panel.UpdateWindowUI、self.updatewindowuiwxUpdate\u UI\u递归,但它们不起作用。我不想每次单击菜单项时都创建新面板并将其添加回框架

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

您能解释一下self.panel.LoadConfigFile的作用吗?您也可以在刷新后尝试self.panel.Update。

self.panel.LoadConfigFile只需从文本文件中读取一些信息,并将这些信息用于面板的UI。代码有点长而且凌乱,所以我不在这里发布。刷新后我尝试了self.panel.Update,但它不起作用。未发现错误或异常,但未显示更改。我担心的是LoadConfigFile可能没有按预期的方式更新元素,因为调用Refresh应该足够了。