【问题标题】:How to update the UI of the sub Panel from a parent Frame in wxPython如何从 wxPython 中的父框架更新子面板的 UI
【发布时间】:2011-09-17 05:38:00
【问题描述】:

我有一个主框架 (wx.Frame),其中包含一个菜单栏和一个面板 (wx.Panel)。该面板包含框架的主 UI。我想在单击菜单项时更新面板的 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() 

【问题讨论】:

    标签: wxpython


    【解决方案1】:

    您能否解释一下 self.panel.LoadConfigFile 的作用?您也可以在 Refresh 之后尝试 self.panel.Update()。

    【讨论】:

    • self.panel.LoadConfigFile() 只是从文本文件中读取一些信息并将这些信息用于面板的 UI。代码有点长而且有点乱,这里就不贴了。我在 Refresh() 之后尝试了 self.panel.Update() 但它不起作用。未发现错误或异常,但未出现更改。
    • 我担心 LoadConfigFile 可能不会按照您期望的方式更新元素,因为调用 Refresh 确实应该足够了。
    猜你喜欢
    • 1970-01-01
    • 2020-09-20
    • 2014-05-01
    • 2014-11-03
    • 1970-01-01
    • 2016-09-06
    • 2016-10-18
    • 2011-01-27
    • 2020-05-25
    相关资源
    最近更新 更多