I'm trying to implement a simple ui to show network messages. client.connect() returns a string. However, I get out of space exception and of course no UI updates
allText = ''
class Receive():
def __init__(self, client):
while 1:
try:
text = client.connect()
if not text:
pass
else:
global allText
allText = allText + text + '\n'
except Exception as e: print(e)
class App(thr.Thread):
client = cvClient()
client.login()
client.register()
client.setWorking()
def __init__(self, master):
thr.Thread.__init__(self)
frame = TK.Frame(master)
frame.pack()
self.gettext = tkst.ScrolledText(frame, height=10,width=100)
self.gettext.pack()
self.gettext.insert(TK.END,'Welcome to Chat\n')
self.gettext.configure(state='disabled')
sframe = TK.Frame(frame)
sframe.pack(anchor='w')
self.pro = TK.Label(sframe, text="Client>>");
self.sendtext = TK.Entry(sframe,width=80)
self.sendtext.focus_set()
self.sendtext.bind(sequence="<Return>", func=self.Send)
self.pro.pack(side=TK.LEFT)
self.sendtext.pack(side=TK.LEFT)
def Send(self, args):
self.gettext.configure(state='normal')
text = self.sendtext.get()
if text=="": text=" "
self.gettext.insert(TK.END,'Me >> %s\n'%text)
self.sendtext.delete(0,END)
self.client.send(text)
self.sendtext.focus_set()
self.gettext.configure(state='disabled')
self.gettext.see(TK.END)
def callback(self):
print ("in callback")
self.gettext.configure(state='normal')
global allText
self.gettext.insert(TK.END,'Server >> %s\n'%allText)
self.gettext.configure(state='disabled')
self.gettext.see(TK.END)
root.after(1000, self.callback)
def run(self):
self.callback()
Receive(self.client)
root = TK.Tk()
root.title('Client Chat')
app = App(root).start()
root.mainloop()
This is the error I get
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/innereye/anaconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "cvClient.py", line 332, in run
self.callback()
File "cvClient.py", line 325, in callback
self.gettext.configure(state='normal')
File "/home/innereye/anaconda2/lib/python2.7/lib-tk/Tkinter.py", line 1331, in configure
return self._configure('configure', cnf, kw)
File "/home/innereye/anaconda2/lib/python2.7/lib-tk/Tkinter.py", line 1322, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: out of stack space (infinite loop?)
Any suggestions? I'm not blocking the UI thread or calling it in an infinite loop, so I don't really understand why this is happening.