Hi,
I am having a problem with function and class syntax.
I have one class (MakePanel1) that creates a button and label. The button-click event of the button is linked to a function (daclick1) that changes the text of the label. This works well.
I have another class (MakePanel2) that creates a second button. I want this second button to call the button-click function of the first button.
My incorrect call MakePanel1.daclick1()
whilst in the MakePanel2 class produces the error ' TypeError: unbound method daclick1() must be called with MakePanel1 instance as first argument (got nothing instead) '.
#!/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(wx.Panel):
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()
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()
How do I call the button-click function of button 1 whilst in the button-click function of button 2 ?
Any assistance appreciated. Thanks.