Aramanethota
Aramanethota

Reputation: 693

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.

Upvotes: 1

Views: 97

Answers (2)

Aramanethota
Aramanethota

Reputation: 693

I did something like this and it worked for me.

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))
        .......
        .......
        panel1 = wx.Panel(panel, wx.ID_ANY,size=(550,200),pos=(25,150))
        self.log = wx.TextCtrl(panel1, wx.ID_ANY, size=(550,200),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)


    def PanelStatus(self,message):
        self.log.AppendText(message)

and used self.PanelStatus("my text") in the other function.

Upvotes: 0

Blckknght
Blckknght

Reputation: 104712

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").

Upvotes: 1

Related Questions