Python Forum
Button to stop while loop from another script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button to stop while loop from another script
#4
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().
Reply


Messages In This Thread
RE: Button to stop while loop from another script - by deanhystad - Sep-25-2023, 05:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 1,000 Nov-16-2022, 07:58 PM
Last Post: Winfried
  How to break out of a for loop on button press? philipbergwerf 6 1,897 Oct-06-2022, 03:12 PM
Last Post: philipbergwerf
  non-stop ping script kucingkembar 1 1,420 Aug-23-2022, 06:29 AM
Last Post: menator01
  get out of while loop and stop repeat Frankduc 11 3,186 Apr-26-2022, 10:09 PM
Last Post: deanhystad
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,607 Sep-27-2021, 05:40 PM
Last Post: rondon442
  how to loop a script? ZYSIA 1 2,076 Jul-22-2021, 06:46 AM
Last Post: Gribouillis
  Stop/continue While loop block Moris526 68 26,769 Mar-28-2021, 09:21 PM
Last Post: Larz60+
  Using a button to kill and restart a script duckredbeard 3 3,418 Sep-01-2020, 12:53 AM
Last Post: duckredbeard
  How can I stop the script when I run the game on my own computer? StatTark 2 2,310 Jun-19-2020, 11:20 AM
Last Post: StatTark
  for loop script over telnet in Python 3.5 is not working abhijithd123 1 2,962 May-10-2020, 03:22 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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