I am working on a simple application that will get some values from the Server (continuously) and using those values will draw them on a canvas made using Tkinter. The problem is that the mainloop function of the Tkinter module makes it impossible to get the values as the loop is never entered and since I have to get the values continuously the loop is an infinite loop and in that case the GUI is not visible since the loop keeps on running. So what do I do? How do I proceed?
I read this question and also this question. The answers suggest Twisted. Any other way to do so?
The code for the server is:
import socket
import pickle
import random
import time
data=[]
s=socket.socket()
host=socket.gethostname()
port=12345
s.bind((host,port))
s.listen(5)
c,addr=s.accept()
while True:
data=str(random.randint(100,500))
c.send(data)
time.sleep(1)
c.close
The code for the client is:
import Tkinter as tk
import socket
import pickle
root = tk.Tk()
canvas = tk.Canvas(root, width=800, height=800, borderwidth=0, highlightthickness=0, bg="white")
canvas.grid()
canvas.create_line(170,400,630,400)
canvas.create_line(400,170,400,630)
#draw things on the canvas
s=socket.socket()
c=[]
host=socket.gethostname()
port=12345
s.connect((host,port))
while True:
a=s.recv(1024)
c.append(int(a))
print c
s.close
root.mainloop()