Python Forum

Full Version: TkInter Realtime calculation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I have a program where I receive a real-time data via TCP-IP using sockets, where I want to use one specific data to make a calculation in real-time. Below is the function I call to start a calculation by another function. The value which updates every one second is the "spm_value".

    def on_btn(self):
    if self.after_id:
        self.after_id = None
    self.stroke_rate = spm_value
Here is the function where it makes the calculation. "self.stroke_rate" is the variable I created which is receiving the "spm_value"

def update_stroke(self):
    self.stroke_count += self.stroke_rate
    self.stroke_redonded = round(self.stroke_count, 2)
    self.stroke_amount_label.config(text=f"{self.stroke_redonded} STROKES")
    self.ecd_label.config(text=f"{ecd_value} PPG")
    self.after_id = self.after(1000, self.update_stroke).
When I press the start button, it start to calculate the number, but it starts to calculate only using the last "spm_value" received at the moment the start button was pressed, the calculation is not updating in real-time too if the value changes.

Could you please help me on that?

Thanks in advance!
Need to see how the socket is used
Your indentation is off, so the way that I read it, a button press calls on_btn(), which then calls update_stroke() on the last line of the function. update_stroke then calls itself every second. on_btn() is the only function that uses spm_value and it doesn't get called until the next button click (should the after be calling on_btn).
That indentation has to be a posting error because the program runs. As posted, it is a syntax error that would stop the program from running.