I would like for my client GUI to put the received messages into the chat box however due to part of the GUI not being in the main thread its giving me this error.
RuntimeError: main thread is not in main loop
Client code:
#imports
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('192.168.0.27',5006))
class GUI():
def __init__(self):
#constructor code
def Structure(self):
#appearance code
self.Cons.config(state = DISABLED)
self.receive_thread = Thread(target=GUI.receive, args=(self,))
self.receive_thread.start()
def receive(self):
while True:
msg = s.recv(1024)
received = msg.decode("utf-8")
print(received)
self.Cons.config(state = NORMAL)
self.Cons.insert(END, received+"\n\n")
self.Cons.config(state = Disabled)
self.Cons.see(END)
def transmit(data,self):
encodeddata=data.encode("utf-8")
s.send(encodeddata)
self.Msg.delete(0, 'end')
x=GUI()
x.Structure()