Simple PyQt solution: “how to add an image to a program” – InformTFB

Simple PyQt solution: “how to add an image to a program”

Simple PyQt solution: “how to add an image to a program”

Simple solution according to the source code:


import sys
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QLabel, QApplication)
from PyQt5.QtGui import QPixmap
 
class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):      
        hbox = QHBoxLayout(self)
        pixmap = QPixmap("/home/fil/pictures/Torrents.png")
        lbl = QLabel(self)
        lbl.setPixmap(pixmap)
        hbox.addWidget(lbl)
        self.setLayout(hbox)
        
        self.move(100, 200)
        self.setWindowTitle('Red Rock')
        self.show()        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

API documentation: https://doc.qt.io/qtforpython/api.html

Valery Radokhleb
Valery Radokhleb
Web developer, designer

Leave a Reply

Your email address will not be published. Required fields are marked *