in reply to Re^5: Tk and Threads
in thread Tk and Threads

With a restart I mean undoing everything the thread has done and then starting it again.

I have a TK Gui. The user is pressing the start button. Then a long action is started (in a thread). There is also a cancel button. If the user is pressing the cancel button then the long action shall be stopped immediately. Everything what has been done until now shall be undone (e.g. deleting a file which was created by this thread). When the user then again is pressing the start button the long action shall be started again. Because there are a lot of other GUI-Elements which contain information for the thread a new pressing of the start button has to give this information to thread.

Replies are listed 'Best First'.
Re^7: Tk and Threads
by BrowserUk (Patriarch) on Dec 22, 2010 at 12:27 UTC

    I've shown you how to signal from buttons on your Tk gui to your threads.

    What happens when those signals are received is just a matter of programming.

    If you need to delete a file...program the signal handler code to delete the file.

    Need then to start the thread over, create a new thread and abandon this one.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Thank you

      This was the information I needed. I have to do the cleanup, the abandon and the creation of the new thread in the signal handler.

      Sorry for my confusing answers and my IDLE And WORK states (Now I'll never talk again about these meaningless states). I thought that it is not allowed to create a new thread after Tk was started because this would then make the SW unstable and possibly crashing. That was the reason why I asked and asked again.

      But if you say that it is ok to do it in the signal handler then it is easy and I know what I have to do.

        I thought that it is not allowed to create a new thread after Tk was started because this would then make the SW unstable and possibly crashing

        When you create a new thread, it gets a copy of the state of the thread it is created from.

        If you create your work thread before creating your tk gui, it does contain any of the gui stuff.

        If you then create another new thread from within that first thread, it also will not have any of the tk stuff that you created in the main thread after you started the work thread.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        I thought that it is not allowed to create a new thread after Tk was started because this would then make the SW unstable and possibly crashing.

        You are right to continue believing that.

        Alot of what BrowserUk says may be true, on Windows, which he uses. But on linux, threads work a bit differently.

        Of course, on Gtk2, you can create them after gui init. ;-)


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh