I have two classes in an application and the first is a w开发者_JAVA技巧x class, which is instantiated as follows:
if __name__ == '__main__':
app = wx.App()
ExampleFrame(None, 'Does Nothing')
NewX = X(sys.argv)
app.MainLoop()
The class itself looks like the following:
class ExampleFrame(wx.Frame):
def __init__(self, parent, title):
super(ExampleFrame, self).__init__(parent, title=ttl, size=(600, 600))
self.Centre()
self.Show()
def DrawLine(self, x1, y1, x2, y2):
dc = wx.ClientDC(self)
dc.DrawLine(x1, y1, x2, y2)
def Clear():
self.Hide
self.Show
# NOW DRAW SOME LINES....
The other Class instance is say, Class X, where I try to call ExampleFrame.Clear(), but it fails.
My question is, How do I call the Clear() method in ExampleFrame from Class X? What am I missing?
EDIT: When the python script fails, it does throw some sort of error, but the window closes too quickly to see what it states.
You can assign references of wx objects to variables and at that point you can access their functions like any other object:
ef = ExampleFrame(None, 'Something')
NewX = X(sys.argv, ef)
Now from within X, you'd need to store this reference so other methods can access it:
def __init__(self, argv, ef):
# Some other stuff
self.__ef = ef
Methods of X now have access to your frame:
# X method
def clearFrameFromX(self):
self.__ef.Clear()
精彩评论