0

I am stuck in a problem from couple of days, the problem is very simple. I want to run a code with many functions in it, some functions are related to tkinter gui, one function is related to creating tcp stream, one function is to press the button and send a message on tcp stream. I want all the the processes to run at the same time,like while i see front end gui of tkinter , i also want a backend tcp steams process and when i press the button on tkinter it send message on tcp streams. All processes should be concurrent. I couldn't achieve this in my code. Below is the code.

from tkinter import *
root =Tk()
def func1():
 #tkinter stuff
def func2():
  #button on tkinter window when pressed should send message on tcp stream
def func3():
    serversocket = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)

    # get local machine name
    host = "192.168.0.100"

    port = 21600

  # bind to the port
     serversocket.bind((host, port))

    # queue up to 5 requests
      serversocket.listen(5)

     while True:
        # establish a connection
       clientsocket, addr = serversocket.accept()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Zavi
  • 1
  • 4

1 Answers1

1

The essential problem here is both your network code and your GUI (tkinter) want to run in event loops. As you're only using one thread, only one event loop can run.

Instead of having your networking code inside a while True:, have a look at this answer. It pertains to serial writing instead of network activity, but the same principles apply directly to your case.

Community
  • 1
  • 1
Adam Barnes
  • 2,922
  • 21
  • 27
  • 1
    hi thanks for your comments @Adam Barnes , I am now not stuck in the loop but still have an issue. I get the error of :TypeError: __call__() missing 1 required positional argument 'gui_element' what should i do now – Zavi Nov 12 '16 at 06:14
  • Without seeing the full traceback, I can't really say anything other than guess that you're using `()` instead of `[]` or something, somewhere, but I suspect also that it's a different issue that would require a different question. I recommend you post a new question, and if someone doesn't beat me to it while I'm asleep, I'll check it out. – Adam Barnes Nov 13 '16 at 23:18