编辑子类的状态栏

时间:2013-11-20 22:37:22

标签: python wxpython statusbar

我在wxApp中创建了一个statusBar,但是这个状态栏不能从另一个类编辑:

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

当我取消注释子类的最后一行时,我收到此错误: MainFrame对象没有attribut statusBar 。 如何编辑子类的statusBar文本?

1 个答案:

答案 0 :(得分:0)

你在self.statusBar存在

之前正在实现它
self.PageThree = pageThree(self) #now self.statusBar does not exists ...
self.statusBar = self.CreateStatusBar()  

...切换订单

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