There is no way to interrupt a running function. However, you can put a binding on <ButtonRelease-1>
for the button, and in that binding you can set a flag. Then, in task13
you can check for that flag at the top of your loop. You will also need a binding on <ButtonPress-1>
to start the loop, since the command
is tied to the release of the mouse button over the button widget.
This will only work if, while in the loop, you service events. If #do stuff
blocks the event loop there's nothing you can do, except to run that code in a separate thread or process.