One solution to fix problem is to have MakePanel2 inherit MakePanel1, then you only need to create instance of MakePanel1 in MakePanel2. For some odd reason wx.BoxSizer() gets confused with the label location. Look the code over.
#!/usr/bin/python
import wx
import time
class MakePanel1(wx.Panel):
def __init__(self, Parent, *args, **kwargs):
wx.Panel.__init__(self, Parent, *args, **kwargs)
self.dalabel = wx.StaticText(self, -1, " panel 1 label ")
self.dabutton1 = wx.Button(self, label="button 1")
self.dabutton1.Bind(wx.EVT_BUTTON, self.daclick1 )
self.bs1 = wx.BoxSizer(wx.HORIZONTAL)
self.bs1.Add(self.dabutton1,0)
self.bs1.Add(self.dalabel,0)
self.SetSizer(self.bs1)
def daclick1(self, event):
self.dalabel.SetLabel(str(time.time()))
class MakePanel2(MakePanel1):
"""Note that MakePanel2 inherits MakePanel1"""
def __init__(self, Parent, *args, **kwargs):
wx.Panel.__init__(self, Parent, *args, **kwargs)
self.dabutton2 = wx.Button(self, label="button 2")
self.dabutton2.Bind(wx.EVT_BUTTON, self.daclick2 )
self.bs2 = wx.BoxSizer(wx.HORIZONTAL)
self.bs2.Add(self.dabutton2,0,wx.ALL,20)
self.SetSizer(self.bs2)
def daclick2(self, event):
#MakePanel1.daclick1() # gives error, need to make instance first
self.Panel1 = MakePanel1(self)
self.Panel1.daclick1(self)
class DisFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.Panel1 = MakePanel1(self)
self.Panel2 = MakePanel2(self)
bs = wx.BoxSizer(wx.VERTICAL)
bs.Add(self.Panel1,1,wx.EXPAND);
bs.Add(self.Panel2,1,wx.EXPAND);
self.SetSizer(bs)
self.Fit()
if __name__ == '__main__':
app = wx.App()
daframe = DisFrame(None)
daframe.Show()
app.MainLoop() bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184