title: How to Access Functions from Methods in Python
body: <p><strong>Question</strong></p>
  
  <p>Within the same class, how can one access a function from within a method?</p>
  
  <p><strong>Background</strong></p>
  
  <p>Hello World! I am currently working on a GUI IM program using Tkinter. To send messages over the socket, I need to access functions from methods. My <code>self.network</code> method has a function called <code>send_message()</code> which I want to access. </p>
  
  <p><strong>Code</strong></p>
  
  <p>To access it, I have tried to use this code:</p>
  
  <pre><code>def messageFun(self):
  
      //Other widgets are here//
  
      self.send = Button (self.messageFrame, text = "Send",
                          command = self.network(send_message()))
      self.send.grid(row = 1, column = 1, sticky = S)
  </code></pre>
  
  <p>The <code>self.network</code> method and <code>send_message</code> function are as follows:</p>
  
  <pre><code>def network(self):
  
      def send_message():   
              #Send some data to the remote server
              message = self.message.get("0.0",END)
  
              try:
                   #set the whole string
                   s.sendall(message)
              except socket.error:
              #Send Failed
                  print "Send failed"
                  sys.exit()
  </code></pre>
  
  <p>Despite my efforts to debug the code, I am always rewarded with this message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\Python Programs\Sockets\First Project\IM Project\Server GUI InDev.py", line 178, in &lt;module&gt;
      app = Application(root)
    File "D:\Python Programs\Sockets\First Project\IM Project\Server GUI InDev.py", line 73, in __init__
      self.messageFun()
    File "D:\Python Programs\Sockets\First Project\IM Project\Server GUI InDev.py", line 156, in messageFun
      command = self.network(send_message()))
  NameError: global name 'send_message' is not defined
  </code></pre>