Maybe this short example will help:
# reference across class instances
# from one panel class to another panel class
import wx
import time
class MyPanel1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY,
pos=(0,0), size=(300, 100))
self.SetBackgroundColour("green")
self.button = wx.Button(self, label=" panel1 button ")
self.button.Bind(wx.EVT_BUTTON, self.buttonClick )
def buttonClick(self, event):
"""
use the panel2 label and
reference via the parent --> frame
"""
# display something that indicates a change
s = time.strftime("%H:%M:%S", time.localtime())
frame.panel2.label.SetLabel(s)
class MyPanel2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY,
pos=(0, 100), size=(300, 100))
self.SetBackgroundColour("yellow")
self.label = wx.StaticText(self, wx.ID_ANY, " panel2 label ")
app = wx.App(0)
# create a frame, no parent, default ID, title, size
caption = "wx.Panel()"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(300, 220))
# note that frame is the parent for the two panels
frame.panel1 = MyPanel1(frame)
frame.panel2 = MyPanel2(frame)
frame.Show(True)
app.MainLoop()