Twisted and Tkinter

Chris cesugden at gmail.com
Thu Apr 27 11:32:38 EDT 2006


Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
    return self.func(*args)
TypeError: unbound method sendMessage() must be called with ChatFactory
instance
 as first argument (got nothing instead)

I have simplified the code as well, now attached below:

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

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

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




More information about the Python-list mailing list