Site icon Python GUI

Learn How To Build Python GUI Apps For Windows

How about combining the strength of Delphi and Python for your applications to provide first-class solutions for your customer needs? Thinking about how to do it? Don’t worry! Python4Delphi does for us. Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi and C++Builder. They let you easily execute Python scripts, create new Python modules and new Python types. This post will guide you on how to use these components, create a VCL application, run a simple python script in it, and gets the output.

Python4Delphi Demo1 Sample App shows how to run a Python Script by typing the python code in a Memo, execute and populate the result in another Memo. You can find the Demo1 source on GitHub.

Prerequisites: Download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out this video Getting started with Python4Delphi

Components used in Python4Delphi Demo1 App:

1.TPythonEngine: A collection of relatively low-level routines for communicating with Python, creating Python types in Delphi, etc. It’s a singleton class. Some of the key properties for the component listed here.

2.TPythonGUIInputOutput: Inherited from TPythonInputOutput (which works as a console for python outputs) Using this component Output property you can associate the Memo component to show the output.

3.TMemo: A multiline text editing control, providing text scrolling. The text in the memo control can be edited as a whole or line by line.

You can find the Python4Delphi Demo1 sample project from the extracted GitHub repository ..\Python4Delphi\Demos\Demo01.dproj. Open this project in RAD Studio 10.4.1 and run the application.

Implementation Details:

[crayon-6622afed46da1250677428/]

Load the script to the Memo1 from a file using the code

[crayon-6622afed46f02030448121/]

Save the Script to the file using the code,

[crayon-6622afed46f06183963083/]
<strong>Python4Delphi Demo1<strong>

Check some of the Python GUI tutorials available for Python4Delphi here

Exit mobile version