I am designing a GUI using the wxPython toolkit, which means it's being written in python2. However, I want to use python3 for the actual application code. How would I go about calling my python3 code from the GUI?
10
votes
2 Answers
17
votes
5
votes
You can run the application code as a shell script.
from subprocess import call
exit_code = call("python3 my_python_3_code.py", shell=True)
You can also pass in terminal arguments as usual.
arg1 = "foo"
arg2 = "bar"
exit_code = call("python3 my_python_3_code.py " + arg1 + " " + arg2, shell=True)
If you want to collect more information back from the application you can instead capture stdout as describe here: Capture subprocess output
If you want to fluidly communicate in both directions a pipe or socket is probably best.