Site icon Python GUI

This Is How Python’s Self Works In Windows Development

This Is How Pythons Self Works In Windows Development

Whenever object-oriented programming is done in Python, then we will often come across the self method as their first parameter. This article explains the main concept of self method in Python for Windows development.

self represents the instance of the class in Python. By using the “self” keyword we can access the attributes and methods of the class in Python. It binds the attributes with the given arguments.

The reason you need to use self because Python does not use the @ syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which the method belongs be passed automatically, but not received automatically: The first parameter of methods is the instance the method is called on.

Here is the basic example of how we can use self keyword:

[crayon-662e3c1c76d52542993793/]

The output in PyScripter IDE:

Here is another example:

[crayon-662e3c1c76d5d450114445/]

The output in PyScripter IDE:

Note: Self is a convention and not a real Python keyword. self is a parameter in function and the user can use another parameter name in place of it. But, it is advisable to use self to increase our code readability.

The following code is the working example of using self parameter in the context of creating GUI using DelphiVCL library:

[crayon-662e3c1c76d5f791359892/]

And here is the GUI result:

You can browse more complex demo here.

 

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

Exit mobile version