Python GUI

Easily Learn How To Use Python Partial Functions In A Delphi Windows GUI App

screen-shot-2021-01-23-at-5-34-30-pm

Python is an incredibly popular general purpose object oriented language that can be used in many ways. Not only is it used by experts in the field of Data Science and Data Analytics, it is also used by many Universities as a means for teaching beginners. The power of Python can grow exponentially when it is paired with the right tools and that brings us to Python4Delphi which is a remarkable set of components that work together 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 the following tutorial, we will demo the methods used to define and user partial functions with the aide of P4D’s excellent GUI support.

Prerequisites: Before we begin working, it is essential you 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.

Now in order to demonstrate P4D GUI, we must proceed by creating a VCL application. This can be achieved by running the Demo1 project available at the following gitHub repository link. When we run the Demo1 project, it 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:

The ability to call Partial functions has been packaged within the Functools library of Python. It is incredibly useful when dealing with code that requires flexibility. Partial functions allow the developers to call normal functions with some of the arguments already filled. So for example if the developer has to to use a function multiple times but only needs to change one particular argument, they can utilize the power of Partial functions. Let’s take a look at this in code.

but what if we want to fix the third argument, keeping the first two arguments programmable? The solution to this would be simple. We will make a simple change in the partial function, keeping everything else the same. Observe how this fixes the third argument whilst keeping the other two, flexible.

In the screenshot below, “Part 1” is the result from the first code snippet. Whereas “Part 2” is the result from the second code snippet.

screen-shot-2021-01-19-at-2-13-18-pm-4009430

Check out some more cool tutorials on Python4Delphi over here.

close
Related posts
DelphiLearn PythonPythonPython GUIRAD Studio

Why You Should Know About SQLite For Your Windows Apps

Learn PythonPythonPython GUIVideos

How To Make Matplotlib Charts To Visualize Data

DelphiPythonPython GUIWindows

What You Need To Create A Secure Python Password Generator

DelphiPythonPython GUIWindows

How To Make A GUI For Learning Python Using Turtle Library

Leave a Reply

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

en_USEnglish