Sep-25-2023, 05:17 PM
What you are asking cannot be done. If your GUI calls a function, it will not process any button press events until the function is done running and the mainloop() function is allowed to run. You can push your stop button as many times as you want and nothing will happen if mainloop() is blocked by some function. Doing what you want will require significant changes.
One approach you could try is running your B script in a separate thread or process. This lets the A script mainloop() function run while the B script while loop is trying to connect. You will need to write the B script to allow ending the loop, and provide a means for A script to signal B script that it is time to stop trying to connect. A global variable should work for this.
A second approach is to break up script B into multiple functions, each function taking a small amount of time to execute. You would then use tkinter.after() to implement a loop in script A, calling the functions in script B.
I cannot suggest which approach to use without knowing more about the code that is blocking mainloop().
One approach you could try is running your B script in a separate thread or process. This lets the A script mainloop() function run while the B script while loop is trying to connect. You will need to write the B script to allow ending the loop, and provide a means for A script to signal B script that it is time to stop trying to connect. A global variable should work for this.
A second approach is to break up script B into multiple functions, each function taking a small amount of time to execute. You would then use tkinter.after() to implement a loop in script A, calling the functions in script B.
I cannot suggest which approach to use without knowing more about the code that is blocking mainloop().