How to set a window icon in PyQt5

 

In this post, I'm going to explain about adding window icons in PyQt5. Not like other Gui packages, you can add an image to a window using a simple code in PyQt5. because PyQt5 has built-in functionalities to load an image. Also, it is directly supporting to add image icons. 

This is the built-in icon after we create a window in PyQt5. 


setWindowIcon(QtGui.QIcon("Your_Icon.png")) -- This is the syntax we are using to put an image in the PyQt5 window. 

Note: You need to keep in mind that .png images are only supporting to the window icons in PyQt5



You guys need to know another thing, I'm using just the QIcon function to load the image. In there I'm not using full code QtGui.QIcon function. because I import the QtGui functions directly with 
        from PyQt.QtGui import *
    so, you don't need to mention the QtGui part in the code. 

If you have questions regarding this tutorial you can put them in the below comment section. It's my pleasure to answer them. 

Post a Comment

0 Comments