0

I am trying to create a GUI. I need to execute another python script while the GUI is active. (The GUI is supposed to process the data from this execution) Because I created the GUI using Tkinter, I am unable to execute another file in the python terminal.

How can I solve this problem?

5
  • python has forked tongue Commented Mar 9, 2013 at 18:53
  • @stark need help, since am a beginner to python.. Commented Mar 9, 2013 at 18:58
  • stackoverflow.com/questions/15057789/… Commented Mar 9, 2013 at 19:01
  • This seems to be a similar question: <stackoverflow.com/questions/459083/…> Commented Mar 9, 2013 at 19:15
  • @stark Can u explain a little more about it or can u give an example. Answers given to the above question is confusing me... Commented Mar 9, 2013 at 19:16

1 Answer 1

1

You don't need to launch another interpreter.

You can simply execute the code from the other script in a separte thread or process.


Refactor your "other" script

You want your "other" script to be callable from another script. To do so, you'll just need a function that does what your script used to do.

#other.py

def main(arg1, arg2, arg3):
    do_stuff(arg1, arg2)
    more_stuff(arg2, arg3)
    other_stuff(arg1, arg3) 
    finish_stuff(arg1, arg2, arg3)

Execute the code in another thread

In your main script, when you want to execute the code from other.py, start a new thread:

 #script.py

 from threading import Thread

 from other import main

 thread = Thread(target = main)
 thread.start() # This code will execute in parallel to the current code

To check that whether your work is done, use thread.is_alive(). To block until it finishes, use thread.join()

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Thomas. I got an answer similar to this from the following link, this is what i was looking for.. youtube.com/watch?v=TE7ysx3a7zU

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.