¿Devolución de llamada cronometrada dentro de Tkinter?

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?

¡Gracias!

preguntado el 05 de mayo de 13 a las 21:05

1 Respuestas

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)

contestado el 05 de mayo de 13 a las 21:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.