# -*- coding: utf-8 *-* import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from jythonfx import fix fix.getJavaFX() #need only for older than Java 8 version from jythonfx.application import Application from javafx.scene import control, layout, Scene from jythonfx.event import EventHandler as EH class HiJavaFX(Application): def start(self, stage): ''' start - mine method of App arg stage - needed to change App's window ''' self.title = "JythonFX" label = "Click Me!" button = control.Button(label) #crate button button.setOnAction(EH(self.OnButtonClicked)) #set button event on click self.pane = layout.StackPane() #create layout of scene self.pane.getChildren().add(button)#add button to scene self.width = 300 self.height = 250
# -*- coding: utf-8 *-* import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from jythonfx import fix fix.getJavaFX() from jythonfx.application import Application from javafx.scene import Scene from jythonfx.event import EventHandler as EH from jythonfx.fxml import FXMLLoader from javafx.scene.layout import AnchorPane class Layout(FXMLLoader, AnchorPane):#second class must, be the same as root in FXML file def __init__(self): super(Layout, self).__init__("FXMLSample.fxml")#FXML file to load self.Button.setOnAction(EH(self.OnClick))#The name of Widget must be the same as his id in FXML File self.clicked = False self.firstText = self.Text.getText() self.TextScaleX = self.Text.getScaleX() self.TextScaleY = self.Text.getScaleY() def OnClick(self, event): if not self.clicked: self.Text.setScaleX(self.TextScaleX/2) self.Text.setScaleY(self.TextScaleY/2) self.Text.setText("Hello FXML!") self.clicked = True else: self.Text.setScaleX(self.TextScaleX)