3

I have a TKinter GUI that interacts with an outside program by writing data to it and reading data from it over a UDP connection. The external program sends a status message at 1Hz, and I would like to have a looping callback within my TKinter class that receives that data, but I'm not quite sure how this is done. In a simplified form, here's what I have:

class App:
    def __init__(self,master):
        # Code that creates all the gui buttons, scales, etc

    def SendValues(self,event):
        # Code that sends the values of all the scales upon a button press

    def ReceiveValues(self):
        # Code that receives UDP data and then sets Tkinter variables accordingly

I want to have the ReceiveValues method execute once per second. How do I do this without interrupting all the other Tkinter events that could be happening?

Thanks!

1

1 Answer 1

2

Figured out my own question after doing some poking around. Timed callbacks can be accomplished with the .after() method:

class App:
    def __init__(self):
        self.root = tk()

    def SendValues(self,event):
        # Code that sends the values of all the scales upon a button press

    def ReceiveValues(self):
        # Code that receives the values and sets the according Tkinter variables
        self.root.after(1000, self.ReceiveValues)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.