twisted and tkinter chat client

C

Chris

Hi,

Sorry for reposting but I changed my code and received a new error
message so I thought I would try it on the group again. I have a
working server and this is meant to be a chat client using tkinter that
connects to the server and sends messages. However I receive this error
message when I click the send button:

Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args)
File "C:\Documents and Settings\chris\Desktop\Python\client.py", line
30, in sendMessage
self.sendLine("Test")
AttributeError: ChatFactory instance has no attribute 'sendLine'

Any help really appreciated. Thanks to anyone who has already tried.

The code is here:
from twisted.internet import reactor
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.protocols.basic import LineReceiver
from Tkinter import *
from twisted.internet import tksupport

class ChatClient(LineReceiver):

def connectionMade(self):
self.sendLine("Hello server")

def lineReceived(self, line):
print line

def connectionLost(self, reason):
pass


class ChatFactory(ClientFactory):

protocol = ChatClient

def clientConnectionFailed(self, connector, reason):
reactor.stop()

def clientConnectionLost(self, connector, reason):
reactor.stop()

def sendMessage(self):
self.sendLine("Test")

chat = ChatFactory()
root = Tk()
b1 = Button(root,text="Send")
b1.configure(command=chat.sendMessage)
b1.pack()
tksupport.install(root)

reactor.connectTCP('localhost',8885,ChatFactory())
reactor.run()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top