我有一个wxPython应用程序,其代码如下所示。我想设置MyFrame类的属性值,但我无法引用它。
我该如何使这个代码工作?亲子参考问题python
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.gauge_1 = wx.Gauge(self, -1)
self.notebook_1=myNotebook(self, -1)
class myNotebook(wx.Notebook):
def __init__(self, *args, **kwds):
wx.Notebook.__init__(self, *args, **kwds)
self.other_class_1=other_class()
self.other_class_1.do_sth()
class other_class(object):
def do_sth(self):
gauge_1.SetValue(value) #doesn't work of course, how do I do this?
我不觉得你可以在没有先解释'other_class'的作用是什么的情况下得到合适的答案吗?它真的应该是一个通用的类,它保存对你的MyFrame实例的引用吗?这里有什么用法?就我们所知,MyFrame1可以有一个全局实例,可以通过'other_class'实例直接访问。 – jdi 2012-03-10 00:06:56
我刚刚意识到'other_class'是什么后,足够盯着足够。奇怪的 – jdi 2012-03-10 00:11:58