title: GUI and networking in Python
body: <p>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?</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/2991852/networking-application-and-gui-in-python">this</a> question and also <a href="https://stackoverflow.com/questions/700905/how-to-design-multi-threaded-gui-network-application">this</a> question. The answers suggest Twisted. Any other way to do so?</p>
  
  <p>The code for the <strong>server</strong> is:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The code for the <strong>client</strong> is:</p>
  
  <pre><code>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()
  </code></pre>