[Tkinter] TkInter Realtime calculation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] TkInter Realtime calculation (/thread-38554.html) |
TkInter Realtime calculation - marlonsmachado - Oct-28-2022 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_cancel(self.after_id) self.after_id = None self.button.config(text="Start") self.stroke_rate_entry.config(state="normal") return self.stroke_rate = spm_value self.button.config(text="Pause") self.stroke_rate_entry.config(state="disabled") self.update_stroke()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! RE: TkInter Realtime calculation - deanhystad - Oct-28-2022 Need to see how the socket is used RE: TkInter Realtime calculation - woooee - Oct-28-2022 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). RE: TkInter Realtime calculation - deanhystad - Oct-28-2022 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. |