【问题标题】:edit StatusBar from ChildClass从子类编辑状态栏
【发布时间】:2013-11-20 22:37:22
【问题描述】:

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

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 对象没有属性状态栏。 如何编辑子类的 statusBar 文本?

【问题讨论】:

    标签: python wxpython statusbar


    【解决方案1】:

    你在 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 ...
    

    【讨论】:

    • 哦该死的,德国来晚了——这太容易了=(谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多