Pyside2 Window Icon | Python GUI

Pyside2 Window Icon | Python GUI – In this Pyside2 GUI Development article i want to show you how to create Window Icon.

so before this we had some articles on Pyside2 GUI Development, you can check them in the below link.

 

Check Python GUI Development With Pyside2

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

 

 

So now this is the complete code for Pyside2 Window Icon | Python GUI

 

 

 

So in the above code first we have imported our classes from Pyside2 library

 

 

 

And this is our main window class that inherits from QWidget, in that class we are going to add the window title , window geometry and minimum width and height for the window.

also you can check Python Object Oriented Programming Articles in the link. Python Object Oreinted Programming.

also we have added the setIcon() method in this class.

 

 

 

This is the method that we are going to set our icon, make sure that you have an icon in your working directory, as i have already added an icon to

my working directory. so in here first you need to create the QIcon object and after that you set the window icon by using setWindowIcon().

 

 

 

So in here every PyQt5 application must create an application object. The sys.argv parameter is a list of arguments from a command line.

Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.

 

 

 

In here we create the object of our main window class.

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.

The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.

 

 

 

So now run the complete code and this will be the result, a window with an icon.

 

Pyside2 Window Icon | Python GUI
Pyside2 Window Icon | Python GUI

 

 

 

Also you can watch the complete video for this article

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×