2013-11-20 70 views
0

我在wxApp創建一個狀態,但這種狀態欄是不是從另一個類編輯:編輯狀態欄從ChildClass

import wx 

class MainFrame(wx.Frame): 
    def __init__(self): 
     wx.Frame.__init__(self, None, wx.ID_ANY, 
          "Pyramid App",size=(800,600),style= wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX) 

     self.SetBackgroundColour((232,232,232)) 
     self.p = wx.Panel(self,size=(800,600),pos=(0,0)) 
     self.PageThree = pageThree(self) 
     self.statusBar = self.CreateStatusBar() 
     self.statusBar.SetFieldsCount(2) 
     self.statusBar.SetStatusText('status bar from MainFrame', 0) 
     self.ChangeStatusBar('foo',1) 

    def ChangeStatusBar(self,txt,field): 
     self.statusBar.SetStatusText(txt,field) 

class pageThree(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent=parent,size=(800,525)) 
     self.myparent=parent 
     self.pageThree=wx.Panel(self,size=(800,525)) 
     wx.StaticText(self.pageThree, -1, 'this is page three', (20,20)) 
     #self.myparent.ChangeStatusBar('bar',1) 

if __name__ == "__main__": 
    app = wx.App() 
    MainFrame().Show() 
    app.MainLoop() 

當我取消我的childclass的最後一行,然後我得到這個錯誤:大型機對象沒有屬性狀態條形碼。 如何編輯子類中的statusBar文本?

回答

0

你self.statusBar存在

self.PageThree = pageThree(self) #now self.statusBar does not exists ... 
self.statusBar = self.CreateStatusBar() 

之前instansiating它...切換順序

self.statusBar = self.CreateStatusBar() 
self.PageThree = pageThree(self) #now self.statusBar exists ... 
+0

哦該死的,它是晚於德國 - 這是太容易=(謝謝! – Munchkin