0

I am coding app for measure power during squat. Its taking data from arduino, then there is a method which calculating it on power. This calculations are in while loop. When i press start calculation button my app freeze. I am sure that i have to use Threads here. I was looking for some basic example how to do it, but without any success. This is how its looks atm:

1.Button:

btn = tk.Button(self, text="Zacznij pomiary", command=lambda: methods.clicked(self.txtEntry, self.txtEntry1, self.txtEntry2))
        btn.grid(column=0, row=3)
  1. Method: (read data is a function that making calculation each milisecond in while loop)
def clicked(a, b, c):
    if len(a.get()) == 0 or len(b.get()) == 0 or len(c.get()) == 0:
        popupmsg("Wprowadź poprawne dane!")
    else:
        readData(float(a.get()), float(b.get()), float(c.get()))

I am looking for some examples how to implement stop button here.

1 Answer 1

1

In clicked:

    else:
        global keepGoing
        keepGoing = True
        threading.Thread( target=readData, args=(float(a.get(),float(b.get(),float(c.get()),daemon=True)

In readData:

    while keepGoing:
         ... do stuff ...

Then, make a stop button connected to:

def onStopButton():
    global keepGoing
    keepGoing = False
Sign up to request clarification or add additional context in comments.

3 Comments

In that case i dont need thread when i am implementing btn? And daemon is importing from systemd.daemon ?
stackoverflow.com/questions/4330111/… okay thats work, thanks a lot :)
daemon=True means you don't have to wait for it to end with t.join().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.