Can a Tkinter GUI check for abort script:

M

Michael Yanowitz

Hello:

I have successfully implemented a Tkinter GUI which has
this (simplified here for explanation):
+-------------------------------------+
| filename: [ ./test3.py] |
| |
| [Run Script] |
+-------------------------------------+

But, now what I would like to do while the script is
running, is replace the "Run Script" with "Abort Script".

+-------------------------------------+
| filename: [ ./test3.py] |
| |
| [Abort Script] |
+-------------------------------------+

So, every tenth of a seconds or ??? better time, I
would like to 'return' to the GUI and check if the
"Abort Script" button has been pressed.
How do I do this? Or is there a better way to
implement this?

Thanks in advance:
Michael Yanowitz
 
D

Dennis Lee Bieber

Hello:

I have successfully implemented a Tkinter GUI which has
this (simplified here for explanation):
+-------------------------------------+
| filename: [ ./test3.py] |
| |
| [Run Script] |
+-------------------------------------+

But, now what I would like to do while the script is
running, is replace the "Run Script" with "Abort Script".

That should be the easy part... (I'm not a Tkinter tinker, so can't
give specifics)
So, every tenth of a seconds or ??? better time, I
would like to 'return' to the GUI and check if the
"Abort Script" button has been pressed.
How do I do this? Or is there a better way to
implement this?
This is going to be more difficult... ONE) you should not have
/left/ the GUI so there should be no need to return to it... That is,
pushing [run] should invoke a very short function that returns to the
mainloop event handler with only a minimal pause while processing.

TWO) If your "script" is a heavy number cruncher, you probably need
to start a thread to process it -- this lets it operate in parallel with
the GUI mainloop. The thread should have some sort of loop that tests an
attribute for the "abort signal" (this is NOT testing the GUI button for
presses -- rather the GUI [abort] is a short function that will set the
signal attribute so the thread can read it). When the signal is set, the
thread should clean-up and exit.

If the "script" is some external program, you'll need to get
trickier in figuring out how to kill it.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
H

hg

Michael said:
Hello:

I have successfully implemented a Tkinter GUI which has
this (simplified here for explanation):
+-------------------------------------+
| filename: [ ./test3.py] |
| |
| [Run Script] |
+-------------------------------------+

But, now what I would like to do while the script is
running, is replace the "Run Script" with "Abort Script".

+-------------------------------------+
| filename: [ ./test3.py] |
| |
| [Abort Script] |
+-------------------------------------+

So, every tenth of a seconds or ??? better time, I
would like to 'return' to the GUI and check if the
"Abort Script" button has been pressed.
How do I do this? Or is there a better way to
implement this?

Thanks in advance:
Michael Yanowitz

It depends: As you cannot "kill" a thread in Python, you need some mechanism
to stop your script another way (is that a python script or
a .sh / .bat ? ... from what you're writing, it seems you're calling some
external entity which just might launch a bunch of processes)

So do you or not control the inner workings of that external script ?

If you don't, then "killing" might be the way as posted / clearly the
methord will change from environment to environment.

hg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top