Python - Best way to integrate Java GUI and python code [closed]

若如初见. 提交于 2020-06-08 15:03:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!