Search code examples
pythonpython-2.7wxpython

call a function from another function within the class


My class is,

 class MainFrame(wx.Frame):
     def __init__(self,parent,ID,title):
         wx.Frame.__init__(self, parent, ID, title, style=wx.DEFAULT_FRAME_STYLE ^   wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX,size=(600,500))
         wx.Frame.CenterOnScreen(self) 
         ..........
         ..........
         panel1 = wx.Panel(panel, wx.ID_ANY,size=(550,200),pos=(25,150))
         log = wx.TextCtrl(panel1, wx.ID_ANY, size=(550,200),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

     def PanelStatus(message):
         ...............

I want to call method Panel1 from function 'init' in the function 'PanelStatus' and later call this function in the other class.How to do that?? I am very new to programming language.Help me out.


Solution

  • First, you need to give your PanelStatus function a new first argument self. That's because it's a method, and methods will automatically get the instance they are called on passed as the first argument (the name self is a convention).

    Then, you can call it from __init__ with self.PanelStatus("some message"). If other code in other parts of your program have a reference to a MainFrame instance, they can call myMainFrame.PanelStatus("some other message").