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!

user1636547
  • 304
  • 1
  • 3
  • 13

1 Answers1

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)
user1636547
  • 304
  • 1
  • 3
  • 13