Can a Tkinter GUI check for abort script:

Discussion in 'Python' started by Michael Yanowitz, Dec 18, 2006.

  1. 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
     
    Michael Yanowitz, Dec 18, 2006
    #1
    1. Advertising

  2. On Mon, 18 Dec 2006 07:37:47 -0500, "Michael Yanowitz"
    <> declaimed the following in comp.lang.python:

    > 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

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Dec 18, 2006
    #2
    1. Advertising

  3. Michael Yanowitz

    hg Guest

    Michael Yanowitz wrote:

    > 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
     
    hg, Dec 19, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus Franz

    Handle user abort inside of a CGI-script

    Markus Franz, Feb 25, 2005, in forum: Python
    Replies:
    0
    Views:
    485
    Markus Franz
    Feb 25, 2005
  2. Marc
    Replies:
    16
    Views:
    611
    Michael Doubez
    Dec 20, 2010
  3. Marc
    Replies:
    11
    Views:
    599
    Michael Doubez
    Dec 20, 2010
  4. Jazzis
    Replies:
    2
    Views:
    275
    Jazzis
    Sep 23, 2003
  5. boczek
    Replies:
    2
    Views:
    170
    boczek
    Jan 4, 2007
Loading...

Share This Page