Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Socket and Tkinter Problem

Reply
Thread Tools

Socket and Tkinter Problem

 
 
Thomas Buschhardt
Guest
Posts: n/a
 
      07-15-2003
Hallo,

I have a problem with Tkinter and the module socket. In a console-window
everything works fine, but in a Tkinter-window I can no more use the
widgets. I found some other mails with this problem, but no solution (I
understand really

Here is my code:
-----------------------------------------------
import win32ui, dde, string, time, os, sys, shutil
from socket import *
from Tkinter import *
from tkFileDialog import *
from tkMessageBox import *
import win32com.client

def sockelserver():
while 1:
HOST = 'localhost'
PORT = 8578
s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
log("wait...")
hs,addr=s.accept()
log("connected with: "+str(addr))
while 1:
data=hs.recv(1024)
if not data:break
if data=="'exit'":break
erg='hallo'
# erg=datawash(data)
log("reiceved: "+data)
hs.send(erg)
hs.close()
if data=="'exit'":break

def log(nachricht):
anzahl_lines=string.count(logtext.get(1.0,END),'\n ')
if anzahl_lines>2000:logtext.delete(0.0,2.0)
logtext.insert(END,time.asctime()+'\t'+nachricht+' \n')
logtext.see(END)
root.update()

root = Tk()
midframe =Frame(root, borderwidth=2, relief=GROOVE)
Label(midframe,text='Logg-Fenster').pack(side=TOP)
scrollbar = Scrollbar(midframe, orient=VERTICAL)
scrollbar.pack(fill=Y, side=RIGHT)
logtext = Text(midframe)
logtext.pack()
logtext.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=logtext.yview)
midframe.pack(padx=2, pady=2)
botframe = Frame(root)
botframe.pack(padx=2, pady=2)
Button(botframe, text='Start',
command=sockelserver).pack(side=LEFT,padx=2,pady=2 )
Button(botframe, text='Exit',
command=root.destroy).pack(side=LEFT,padx=2,pady=2 )
root.title('DDE-Server')
root.mainloop()

--------------------------------------
The function is easy. I want to start a server that waits for connection and
answer with an result. The communication-protocol is printed out in a
Text-window.

Please help me out
Cheers Thomas


 
Reply With Quote
 
 
 
 
Tonino
Guest
Posts: n/a
 
      01-18-2005
hi,

was wondering if you ever got a reply ?
Did you mannage to sort this out ?

I am wanting todo the same thing - just have a window that connects to
a port and displays the data it receives from that port in the window?
Thanks
Tonino

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments