tkinter套接字客户端? [英] tkinter socket client ?
问题描述
我一直在浏览以前的帖子 - 但是由于我对整个tkinter主题缺乏了解b / b
我不知道要看什么
for .. 。
SO - 任何人都可以请帮助这个...?
我有一个python服务器,当它从一个连接客户 -
它将数据发回 - 相当一部分 - 在谨慎的部分 - 围绕
1024字节块...
我创建了一个tkinter客户端,可以简单地连接到
服务器。我遇到的问题是我需要客户端将所有数据写入GUI客户端中创建的Text()小部件 - Text()
小部件是创建为:
self.text = Text(self.center_frame,background =''white'')
scroll = Scrollbar(self.center_frame)
self.text.configure(yscrollcommand = scroll.set)
self.text.pack(side = LEFT,fill = BOTH,expand = YES)
scroll.pack(side = RIGHT,fill = Y)
self.center_frame.pack(side = RIGHT,expand = YES,fill = BOTH)
我有一个带有连接按钮的按钮写在上面,通过调用连接到
服务器:
HOST =''localhost''
PORT = 9000
全球s
for res in socket.getaddrinfo(HOST,PORT,socket.AF_UNSPEC,
socket.SOCK_STREAM):
af,socktype,proto,canonname,sa = res
尝试:
s = socket.socket(af,socktype,proto)
除了socket.error,msg:
s =无
继续
尝试:
s.connect(sa )
除了socket.error,msg:
s.close()
s =无
继续
休息
如果s为None:
print''无法打开套接字''
self.quitButtonClick
现在 - 我如何在
Text()小部件中连续打印服务器发送的数据?
非常感谢
Tonino
2005年1月20日22:25:52 -0800谣言说&q uot; Tonino"
< to ********** @ gmail.com>可能写的:
[套接字客户端的tkinter gui,来自套接字的大量数据]
现在 - 我如何得到服务器发送的数据是否继续打印在
Text()小部件中?
您需要使用:
yourTextWidget.insert(Tkinter.END,data)#插入数据
yourRootWindow.update_idletasks()#更新GUI
-
TZOTZIOY,我说英格兰最好。
发送时要严格,接收时要宽容。 (来自RFC1958)
我真的应该在与人交谈时牢记这一点,实际上......
感谢您的回复。 />
只有一个问题 - 我不知道如何坐在循环中在套接字连接上接受
消息 - 将它们写入Text()小部件
- 刷新GUI - 然后重新开始....
我在哪里放置套接字的循环?
谢谢
Tonino
>只有一个问题 - 我不知道如何坐在循环中在套接字连接上接受消息 - 将它们写入Text()小部件
- 刷新GUI - 然后从头开始....
我在哪里放套接字的循环?
另一个线程?或者使用扭曲,它带有一个tkinter感知的exec循环:
http://twistedmatrix.com/documents/h...eactor#auto16:
-
问候,
Diez B. Roggisch
I have been looking through the previous posts - but with my lack of
knowledge on the whole tkinter subject - I have no clue what to look
for ...
SO - can anyone please help with this ...?
I have a python server that when it gets a connection from a client -
it sends data back - quite a bit of it - in discreet parts - around
1024 byte chunks ...
I have created a tkinter client that makes a simple connect to the
server. What I have a problem with is I need the client to write all
the data to the Text() widget created in the GUI client - the Text()
widget is created as :
self.text=Text(self.center_frame,background=''white '')
scroll=Scrollbar(self.center_frame)
self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT,fill=Y)
self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
I have a button with "Connect" written on it that connects to the
server by calling :
HOST = ''localhost''
PORT = 9000
global s
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
break
if s is None:
print ''could not open socket''
self.quitButtonClick
NOW - HOW do I get the server''s sent data to continuiosly print in the
Text() widget ?
Many thank
Tonino
On 20 Jan 2005 22:25:52 -0800, rumours say that "Tonino"
<to**********@gmail.com> might have written:
[tkinter gui for a socket client, lots of data from the socket]
NOW - HOW do I get the server''s sent data to continuiosly print in the
Text() widget ?
You need to use:
yourTextWidget.insert(Tkinter.END, data) # to insert the data
yourRootWindow.update_idletasks() # to update the GUI
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
thanks for the reply .
just one problem - I do not know how to sit in a "loop" accepting
messages on the socket connection - writting them to the Text() widget
- refreshing the the GUI - and then starting all over ....
where do I put the loop for the socket ?
Thanks
Tonino
> just one problem - I do not know how to sit in a "loop" acceptingmessages on the socket connection - writting them to the Text() widget
- refreshing the the GUI - and then starting all over ....
where do I put the loop for the socket ?
Another thread? Or use twisted, it comes with a tkinter-aware exec-loop:
http://twistedmatrix.com/documents/h...eactor#auto16:
--
Regards,
Diez B. Roggisch
这篇关于tkinter套接字客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!