DelphiLearn PythonPythonPython GUIWindows

Easily Learn How To Use Classes And Objects In Python With A Delphi Windows GUI App

screen shot 2021 01 10 at 10 31 11 pm 8012203

Python is one of the worlds most popular languages with an extensive community support. Which makes it an ideal choice for beginners and experts alike! Delphi, the program behind many stunning visual applications, recognizes the importance of Python is presenting you with Python4Delphi, an excellent set of components that work by wrapping up the Python DLL into Delphi and C++Builder thus enabling its users to view GUI for their Python scripts with ease. In this tutorial, we will demonstrate how we can construct classes and objects using Python with the aide of Python4Delphi’s excellent GUI support.

Prerequisites: Before we begin working, it is essential we Download the latest version of Python for your platform. You can find the installation instructions for Python4Delphi at this link. Alternatively, you can follow the easy instructions found in this video Getting started with Python4Delphi.

For the purpose stated above, we proceed by making a VCL app. This can be achieved by running the Demo1project project which will be made available to you in the following gitHub repository link. We will now proceed to explaining how you can run Demo1but before that, let’s take a look at the prerequisites.

To get started with Python GUI, we will be using a package already provided to us by P4D. This project called Demo1, when run will result in a VCL application titled “Demo of Python”. This application will have two main visual components called Memos. The top Memo will display code whereas the lower Memo will serve as an input area for the Python script by its users.

If you would like to know more about what goes on inside Delphi, in order to create this VCL application you can check out this wonderful article explaining the workings of the Demo1 project here.

The Python Code: 

This particular segment will explain the Python code that we will write to demonstrate how our Demo1 VCL application works. We will be making different types of Classes and use our Python4Delphi GUI to display their components.

What you see above is a simple class that does not need any initializer. This is because all values inside of it have been hard coded. This type of class is rarely used in practice.

The primary difference between this class and the one before is that it isn’t hardcoded. Which means we can create objects of this class for any values that we like. This is primarily because of the initializer function. The initializer function takes arguments from the user and uses those to set the value of the Class’ internal components. In this case, these components were our student’s name, age and class.

This will be our final example where we have created a method within our class. This method is called about_me() and it will simply print out the details of our student instead of making us write several print statements.

screen shot 2021 01 10 at 6 45 21 pm 1289341

Check out some more cool tutorials on Python4Delphi over here.

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?


Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And Matplotlib Library?

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And Pillow Library?

Leave a Reply

Your email address will not be published. Required fields are marked *