2016/7/20 21:22:32 使用QIcon
from PyQt5.Qt import QIconself.setWindowIcon(QIcon('img/0719/Icon.jpg'))
效果:
2016/7/20 21:38:21 加載本地圖片
code:
from PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *from PyQt5.Qt import QDir, QIconimport sysclass Window(QWidget): def __init__(self): super(Window, self).__init__() self.setWindowTitle('Qt_Group') self.resize(500,500) self.setWindowIcon(QIcon('img/0719/TB1AeYWKVXXXXcmXVXXSutbFXXX.jpg_460x460xz.jpg')) self.echoGroup = QGroupBox('Echo') self.echoLabel = QLabel(self) self.echoLabel.setFixedSize(460,460) self.movieImage = QImage('img/0719/TB1AeYWKVXXXXcmXVXXSutbFXXX.jpg_460x460xz.jpg') self.echoLabel.setPixmap(QPixmap.fromImage(self.movieImage).scaled(self.echoLabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) self.echoLayout = QGridLayout() self.echoLayout.addWidget(self.echoLabel, 0, 0) self.echoGroup.setLayout(self.echoLayout) self.Layout = QGridLayout() self.Layout.addWidget(self.echoGroup, 0, 0) self.setLayout(self.Layout) app = QApplication(sys.argv)win = Window()win.show()app.exec_()