V
V
Veln2018-07-10 11:20:27
PyQt
Veln, 2018-07-10 11:20:27

How to set application icon in PyQt5?

The code according to which the application icon is set is given. However, I am unable to
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self) :
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('web.png'))
self.show()
if __name__ == '__main__':
app = QApplication (sys.argv)
ex = Example()
sys.exit(app.exec_())
PS Python 3.6.4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor, 2018-07-10
@Veln

What specifically doesn't work? It is possible that the folder where the program is located simply does not have a file called " web.png " in the folder where the program is located. If it is, then say that it does not work.

L
LilRock, 2022-04-07
@LilRock

icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icon.png"),
QtGui.QIcon.Selected, QtGui.QIcon.On)
MainWindow.setWindowIcon(icon)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question