如何在wxPython中从父框架更新子面板的UI

发布于 2024-12-05 07:54:20 字数 955 浏览 1 评论 0原文

我有一个主框架(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 技术交流群。

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

发布评论

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

评论(1

夏夜暖风 2024-12-12 07:54:20

您能解释一下 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.

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