Site icon Python GUI

Learn To Build A Flexible Hello World Python GUI In A Delphi Windows App

python hello world in python gui

How about combining the strength of Delphi and Python for your applications to provide first-class solutions for your customer needs? Or you are an expert in Delphi who want to also work with Python, as it is a high and growing demand in the market out there?

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 Hello World! script in it, and gets the output.

You can easily build Python GUI apps using your favorite Python language features and libraries for Windows using Delphi and C++Builder and Python4Delphi. In order to run the Python script in Python for Delphi, open and run project Demo1. Then insert the script into lower Memo, click Execute button, and get the result in upper Memo. You can find the Demo1 source on GitHub.

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.

First, open the Demo01.dproj with RAD Studio:

 

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 ..Python4DelphiDemosDemo01.dproj. Open this project in RAD Studio 10.4.1 and run the application.

 

Implementation Details

[crayon-6605b0e65a3a3078541198/]
[crayon-6605b0e65a3ae970367680/]
[crayon-6605b0e65a3b0999974462/]
[crayon-6605b0e65a3b2683937559/]

Python “Hello World” and Mathematical Operations with Python4Delphi.

Congratulations, now you can successfully run Hello World Python GUI In A Delphi Windows App! Which as you may know that even “Hello World!” is often the first program written by people learning to code, it can also be used as a sanity test to make sure that a computer language is correctly installed and that the operator understands how to use it.

From now, the applications are endless and the only limit is your imagination.

 

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.

Exit mobile version