from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel from PyQt5.QtGui import QIcon, QPixmap class MainWindow(QMainWindow): def __init__(self): super().__init__() label = QLabel(self) pixmap = QPixmap('image.png') label.setPixmap(pixmap) self.setCentralWidget(label) self.setWindowTitle("My App") if __name__ == "__main__": app = QApplication([]) window = MainWindow() window.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel from PyQt5.QtGui import QIcon, QPixmap class MainWindow(QMainWindow): def __init__(self): super().__init__() label = QLabel(self) pixmap = QPixmap('image.png') label.setPixmap(pixmap) pixmap2 = QPixmap('image2.png') label.setPixmap(pixmap2) self.setCentralWidget(label) self.setWindowTitle("My App") if __name__ == "__main__": app = QApplication([]) window = MainWindow() window.show() app.exec_()In this example, we create a QLabel object and set its pixmap to the image file using QPixmap. Then we create a new QPixmap object and set the label's pixmap to the new object. This changes the background image of the QLabel to a different image. The package library used in these examples is PyQt5.