2011-09-17 32 views
0

我有一個包含菜單欄和麪板(wx.Panel)的主框架(wx.Frame)。該面板包含框架的主UI。我想在點擊菜單項時更新面板的UI。如何在wxPython中從父框架更新子面板的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() 

回答

0

你能給一些self.panel.LoadConfigFile做什麼的解釋嗎?您也可以在刷新後嘗試self.panel.Update()。

+0

self.panel.LoadConfigFile()只是從文本文件中讀取一些信息並將該信息用於面板的UI。代碼有點長和雜亂,所以我不在這裏發帖。我在Refresh()之後嘗試了self.panel.Update(),但它不起作用。未發現錯誤或異常,但未顯示更改。 – newwave

+0

我的擔心是LoadConfigFile可能不會按照您期望的方式更新元素,因爲調用Refresh確實應該足夠。 – Cathy

相關問題