Python Forum
[Tkinter] TkInter Realtime calculation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] TkInter Realtime calculation
#1
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!
Reply
#2
Need to see how the socket is used
Reply
#3
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).
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Redirecting stdout to TextBox in realtime Gilush 2 9,765 Jun-06-2020, 11:05 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020