I can not organize a cyclical update of the interface. There is a server that, when launched, should output, for example, a notification that it received a new message from the client. Here is the code snippet.

def startServ(): # запускаем его отдельным потоком thread.start_new_thread(taskServer, ()) def taskServer(): print("Server thread started") host = "" port = 50005 sock = socket(AF_INET, SOCK_STREAM) sock.bind((host, port)) sock.listen(10) servStat.put("Ready") # Кидаем сообщение о запуске в очередь ... servStat = queue.Queue() # сама очередь def readServStatus(): # извлечение из очереди try: serverStatus = servStat.get(block=False) except queue.Empty: serverStatus = "Unknown" servLabel["text"] = serverStatus # Сервер запускается из выпадающего меню и действительно работает if __name__ == '__main__': root = Tk() testLabel = Frame(root) testLabel.pack() servLabel = Label(testLabel, text="Server status") root.after(2000, readServStatus) servLabel.pack(side=RIGHT) root.mainloop() 

In practice, the inscription "Server status" is displayed and after a couple of seconds it changes to "Unknown". It no longer responds to state changes, despite the fact that mainloop () is kind of like a loop. How to make her do it?

    1 answer 1

    After installing the new parameters, you need to update the widget using the update method.

     servLabel["text"] = serverStatus servLabel.update() 
    • I still feel a kind of crutch. servLabel = Label(testLabel, text="Server status") line servLabel = Label(testLabel, text="Server status") added the launch of a new thread thread.start_new_thread(readServStatus, ()) , and added a loop to readServStatus (). And if something appears in the queue, then it inserts the desired value. While working. Now I will try your way. - Skotinin