DelphiDelphiVCLLearn PythonPythonPython GUIWindows

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:

The output in PyScripter IDE:

This Is How Python's Self Works In Windows Development. A Pyscripter results window showing the printed results of the code example.

Here is another example:

The output in PyScripter IDE:

This Is How Python's Self Works In Windows Development. A PyScripter results window showing cars enumerated and printed out.

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:

And here is the GUI result:

This Is How Python's Self Works In Windows Development. An example Windows GUI form

You can browse more complex demo here.

 

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

close
Related posts
Python GUIVideos

How To Add A Color Picker To Your Python GUI

Learn PythonPythonPython GUIVideos

Learn Python GUI With Dropdown Menus With Tkinter Video

Learn PythonPython

10 Mistakes Most Developers Make With Python GUIs

Python

Become An Expert With A Python GUI Builder By Watching These 5 Videos

Добавить комментарий

Ваш адрес email не будет опубликован.

ru_RURussian