Question
Within the same class, how can one access a function from within a method?
Background
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 self.network
method has a function called send_message()
which I want to access.
Code
To access it, I have tried to use this 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)
The self.network
method and send_message
function are as follows:
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()
Despite my efforts to debug the code, I am always rewarded with this message:
Traceback (most recent call last):
File "D:\Python Programs\Sockets\First Project\IM Project\Server GUI InDev.py", line 178, in <module>
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