问题
I want to make a desktop GUI that interacts with the user's files (with permission of course). My code to download files and put it in the user's choice of directory is all written in python. There is much more to this code, but everything is written in python.
I want the GUI part to be a desktop app, so the client can easily interact and function the program.
I want to make this GUI in java and have it interact with the python code once someone presses a button.
What are the best approaches to make this happen?
回答1:
I would do it like this:
Process p = Runtime.getRuntime().exec("python app.py");
You can also pass arguments into the python program as command line arguments, like this:
Process p = Runtime.getRuntime().exec("python app.py arg1 arg2");
回答2:
You might be interested in jython
http://www.jython.org
Also, you might think about running Python using JNI - this way, you will be able to keep the state of Python process while still being inside Java:
https://github.com/mkopsnc/keplerhacks/tree/master/python
Everything heavily depends on what you really want to achieve.
来源:https://stackoverflow.com/questions/44992916/python-best-way-to-integrate-java-gui-and-python-code