将JavaFX与Python结合使用
我想知道是否可以使用 JavaFX 设计 GUI ,然后再结合一些 Python 代码(例如制作一个按钮)使用JavaFX,然后在Python中编写处理程序代码以提供一些功能)。
I was wondering if it is possible to design a GUI using JavaFX and afterwards combining with some Python code (for example make a button using JavaFX and then write handler code in Python to give some functionality).
JavaFX非常适合设计一个非常好的GUI,我需要Python来控制机器人(这些库只能在Python中使用)。
JavaFX is great to design a really good GUI and I need Python to control a robot (the libraries are only available in Python).
我浏览了网页,发现 Jython ,但我无法理解它是否允许我使用这些第三方Python库。
I had a look over the web and I found Jython, but I could not understand if it will allow me to use these third parties Python libraries.
有没有人有一个好的建议或我可以看到的任何来源?任何信息都将不胜感激。
Does anyone have a good suggestion or any sources where I can look at? Any information would be appreciated.
提前感谢您。
是的,您可以用Python编写JavaFX UI(Jython):
Yes, you can write your JavaFX UI in Python (Jython):
#!/usr/bin/env jython
'''
"Hello, World!" in Jython and JavaFX
Roughly based on this: http://docs.oracle.com/javafx/2/get_started/hello_world.htm
'''
import sys
from javafx.application import Application
class HelloWorld(Application):
@classmethod
def main(cls, args):
HelloWorld.launch(cls, args)
def start(self, primaryStage):
primaryStage.setTitle('Hello World!')
from javafx.scene import Scene
from javafx.scene.layout import StackPane
primaryStage.setScene(Scene(StackPane(), 320, 240))
primaryStage.show()
if __name__ == '__main__':
HelloWorld.main(sys.argv)
这很容易。我正在这样做。
That is quite easy. I am doing it.
您还可以用Java编写JavaFX UI,并使用对象工厂之类的东西将控制权分派给Python(Jython)代码。更多相关内容: http:/ /www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications
You can also write your JavaFX UI in Java, and use something like the object factories to dispatch control to your Python (Jython) code. More on that here: http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications