The usual way to stop with a button is have your application run in a while loop and have an event structure
that controls the execution of your loop.
setup the logic so that when the button is pressed, the event structure is true, which stops the while loop from running, which stops execution.