面向对象编程风格
# -*- coding: utf-8 -*-
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget
import sys
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUi()
def initUi(self):
self.setGeometry(300,300,300,300)
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('1.PNG'))
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())
截图: