Es bastante simple, le agregas un callback y dejas que ese callback que esta en la clase que contiene el panel derecho e izquierdo, maneje la situación.
Código Python:
Ver originalimport wx
class RightPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.texto = wx.StaticText(self, -1, 'Test', (230,10), style=wx.ALIGN_CENTRE) #<------ Label que quiero cambiar
def setTitle(self, title):
self.texto.SetLabel(title)
class LeftPanel(wx.Panel):
def __init__(self, parent, parent_callback):
wx.Panel.__init__(self, parent=parent)
self.parent_callback = parent_callback
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL)
panel1 = wx.Panel(self, -1)
self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT|wx.TR_DEFAULT_STYLE)
root = self.tree.AddRoot('Programmer')
os = self.tree.AppendItem(root, 'Programas')
pl = self.tree.AppendItem(root, 'Programas en Python 3.4')
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.Cambiar_Texto_Label, id=1)
vbox.Add(self.tree, -1, wx.EXPAND)
hbox.Add(panel1, -1, wx.EXPAND)
panel1.SetSizer(vbox)
self.SetSizer(hbox)
self.Centre()
def Cambiar_Texto_Label(self, event): #<------- Accion para cambiar label
item = event.GetItem()
text = self.tree.GetItemText(item)
self.parent_callback(text)
class Cagador_Ventana(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"Panel",
size=(1100,660))
splitter = wx.SplitterWindow(self)
self.leftP = LeftPanel(splitter, self.parent_callback)
self.rightP = RightPanel(splitter)
splitter.SplitVertically(self.leftP, self.rightP)
splitter.SetMinimumPaneSize(250)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(splitter, 1, wx.EXPAND)
self.SetSizer(sizer)
self.Centre()
self.Layout()
def parent_callback(self, data):
self.rightP.setTitle(data)
if __name__ == "__main__":
app = wx.App(False)
frame = Cagador_Ventana()
frame.Show()
app.MainLoop()