473,698 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Twisted and Tkinter

Does anyone know how to use twisted and tkinter. I have a simple tcp
server
and I want to send messages to it once connected using a tkinter
button? I
have built the code as far as I can but don't know what to do from
here. Any reference I try to put to sendmessage in chatfactory doesn't
seem to work, just brings up error messages.
This is my code:

from twisted.interne t import reactor
from twisted.interne t.protocol import Protocol, ClientFactory
from twisted.protoco ls.basic import LineReceiver
from Tkinter import *
from twisted.interne t import tksupport

class ChatClient(Line Receiver):

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

def lineReceived(se lf, line):
pass

def connectionLost( self, reason):
pass

class ChatFactory(Cli entFactory):
protocol = ChatClient

def clientConnectio nFailed(self, connector, reason):
reactor.stop()

def clientConnectio nLost(self, connector, reason):
reactor.stop()

def sendMessage(sel f):
self.sendLine(" Test")
root = Tk()
b1 = Button(root,tex t="Send")
#b1.configure(c ommand=sendline to server here)
b1.pack()
tksupport.insta ll(root)
reactor.connect TCP('localhost' ,4567,ChatFacto ry())
reactor.run()

Apr 27 '06 #1
9 3430
Posting that error message would be helpful

Apr 27 '06 #2
Sorry. The error message is normally AttributeError: 'NoneType' object
has no attribute 'sendLine'"

jo************@ gmail.com wrote:
Posting that error message would be helpful


Apr 27 '06 #3
"Chris" wrot:
Sorry. The error message is normally AttributeError: 'NoneType' object
has no attribute 'sendLine'"


please post the *entire* traceback, including the part that lists
filenames, line numbers, and source code lines.

</F>

Apr 27 '06 #4
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\li b\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.interne t import reactor
from twisted.interne t.protocol import Protocol, ClientFactory
from twisted.protoco ls.basic import LineReceiver
from Tkinter import *
from twisted.interne t import tksupport

class ChatClient(Line Receiver):

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

def lineReceived(se lf, line):
print line

def connectionLost( self, reason):
pass
class ChatFactory(Cli entFactory):

protocol = ChatClient

def clientConnectio nFailed(self, connector, reason):
reactor.stop()

def clientConnectio nLost(self, connector, reason):
reactor.stop()

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

root = Tk()
b1 = Button(root,tex t="Send")
b1.configure(co mmand=ChatFacto ry.sendMessage)
b1.pack()
tksupport.insta ll(root)

reactor.connect TCP('localhost' ,8886,ChatFacto ry())
reactor.run()

Apr 27 '06 #5
Chris wrote:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\li b\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)
that's another error message, of course... class ChatFactory(Cli entFactory):

protocol = ChatClient

def clientConnectio nFailed(self, connector, reason):
reactor.stop()

def clientConnectio nLost(self, connector, reason):
reactor.stop()

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

root = Tk()
b1 = Button(root,tex t="Send")
b1.configure(co mmand=ChatFacto ry.sendMessage)


umm. what is that line supposed to do ?

if the purpose is to call the sendMessage method of the Chat-
Message instance you're passing to connectTCP, it's probably
better to create the instance first:

chat = ChatFactory()

root = Tk()
b1 = Button(root,tex t="Send")
b1.configure(co mmand=chat.send Message)
b1.pack()
tksupport.insta ll(root)

reactor.connect TCP('localhost' ,8886,chat)
reactor.run()

</F>

Apr 27 '06 #6
it now comes up with the error message

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

Apr 27 '06 #7
"Chris" <ce******@gmail .com> skrev i meddelandet news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
it now comes up with the error message

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


Which is exactly what one would expect from this method

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

if the class you inherit from doesn't provide a sendLine method.

But since you wrote that method, what did you expect it to do ?

(If this is code from some Twisted manual or sample, it's probably time
to double-check your code against the source...)

</F>

Apr 27 '06 #8
There is no manual that's the problem. The sendLine method is part of
LineReceiver which is part of twisted. It's used to send a message over
the transport link. I can get it working by overriding twisted's
methods for example linereceived() or connectionmade( ). But how do I
get it to send a message over the transport to the server by clicking a
tkinter button? There are no examples or documents on the internet that
can help, I've searched for hours.

Apr 27 '06 #9
Fredrik is right, ChatFactory doesn't have sendLine as a method b/c it
doesn't inherit it from ClientFactory. The code: protocol = ChatClient
does do anything within ChatFactory except set the variable. Try out
these.

from twisted.protoco ls.basic import LineReceiver, LineReceiver.se ndLine

or change class ChatFactory(Cli entFactory) --- to:

class ChatFactory(Cli entFactory, LineReceiver):

or tell ChatFactory that sendLine comes from LineReceiver --

class ChatFactory(Cli entFactory):
protocol = ChatClient

def clientConnectio nFailed(self, connector, reason):
reactor.stop()

def clientConnectio nLost(self, connector, reason):
reactor.stop()

def sendMessage(sel f):
self.LineReceiv er.sendLine("Te st")

I'm pretty sure that those should work.

Apr 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4151
by: Paul Moore | last post by:
I hit a problem yesterday with my mail connection. In a desparate attempt to understand what was going on, I wanted to log the connection traffic. After a bit of searching, I found a post on c.l.p from Andrew Bennetts explaining how to run a port forwarder in 2 lines using Twisted. $ mktap portforward -p 8000 -h remote -d 20 $ twistd -f portforward.tap This looked brilliant - all I needed to do was add logging. A quick
1
2454
by: Fazer | last post by:
Hello, I am very interested in fooling around with Twisted Matrix's HTTP Web Server. I was thinking if .rpy scripts would run much faster than traditional CGI scripts? After looking how asynchronous Twisted's framework really is, I have been interested in it. Thanks,
2
7945
by: Mark Carter | last post by:
I'm trying to create a mail server in Twisted. I either get SMTPSenderRefused or SMTPException: SMTP AUTH extension not supported by server. What do I need to do to get it to work?
11
3593
by: mir nazim | last post by:
hi, i m planning to start writing intranet applications and want ur real cool advices for choosing the correct platform. the choice is between the three: 1. Twisted 2. Medusa 3. Zope (i do not know any of the three).
2
2185
by: Qp | last post by:
Is this even possible? I'm designing a simple chat and game client/server as an intro to Python, and it would be nice to represent the different interfaces (public chat room, private chat rooms, game instances) as totally seperate classes and show them in totally seperate windows. Given my basic understanding of Twisted, I see no way of doing this, and my whole GUI is contained in one class. The project is doable this way, it would...
2
2374
by: SeSe | last post by:
Hi, I am new to Twisted. I use a Twisted 1.3.0 on MS Windows XP Home Edition, my python version is 2.3 I try the TCP echoserv.py and echoclient.py example. But the client always fail with following message: Unhandled error in Deferred: Traceback (most recent call last): File "D:\PYTHON23\Lib\site-packages\twisted\internet\default.py", line 134, in
0
1811
by: Chris | last post by:
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__
6
1679
by: Hendrik van Rooyen | last post by:
Hi, I want to do the equivalent of the after thingy in tkinter - setting up in effect a timed call back. My use case is as a "supervisory" timer - I want to set up an alarm, which I want to cancel if the expected occurrence occurs - but its not a GUI app. My googling gets a lot of stuff pointing to optparse...
15
3775
by: Phillip B Oldham | last post by:
Are there any python event driven frameworks other than twisted?
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.