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,PO RT))
s.listen(1)
log("wait...")
hs,addr=s.accep t()
log("connected with: "+str(addr) )
while 1:
data=hs.recv(10 24)
if not data:break
if data=="'exit'": break
erg='hallo'
# erg=datawash(da ta)
log("reiceved: "+data)
hs.send(erg)
hs.close()
if data=="'exit'": break
def log(nachricht):
anzahl_lines=st ring.count(logt ext.get(1.0,END ),'\n')
if anzahl_lines>20 00:logtext.dele te(0.0,2.0)
logtext.insert( END,time.asctim e()+'\t'+nachri cht+'\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(midfr ame, orient=VERTICAL )
scrollbar.pack( fill=Y, side=RIGHT)
logtext = Text(midframe)
logtext.pack()
logtext.config( yscrollcommand= scrollbar.set)
scrollbar.confi g(command=logte xt.yview)
midframe.pack(p adx=2, pady=2)
botframe = Frame(root)
botframe.pack(p adx=2, pady=2)
Button(botframe , text='Start',
command=sockels erver).pack(sid e=LEFT,padx=2,p ady=2)
Button(botframe , text='Exit',
command=root.de stroy).pack(sid e=LEFT,padx=2,p ady=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
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,PO RT))
s.listen(1)
log("wait...")
hs,addr=s.accep t()
log("connected with: "+str(addr) )
while 1:
data=hs.recv(10 24)
if not data:break
if data=="'exit'": break
erg='hallo'
# erg=datawash(da ta)
log("reiceved: "+data)
hs.send(erg)
hs.close()
if data=="'exit'": break
def log(nachricht):
anzahl_lines=st ring.count(logt ext.get(1.0,END ),'\n')
if anzahl_lines>20 00:logtext.dele te(0.0,2.0)
logtext.insert( END,time.asctim e()+'\t'+nachri cht+'\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(midfr ame, orient=VERTICAL )
scrollbar.pack( fill=Y, side=RIGHT)
logtext = Text(midframe)
logtext.pack()
logtext.config( yscrollcommand= scrollbar.set)
scrollbar.confi g(command=logte xt.yview)
midframe.pack(p adx=2, pady=2)
botframe = Frame(root)
botframe.pack(p adx=2, pady=2)
Button(botframe , text='Start',
command=sockels erver).pack(sid e=LEFT,padx=2,p ady=2)
Button(botframe , text='Exit',
command=root.de stroy).pack(sid e=LEFT,padx=2,p ady=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
Comment