Answer the question
In order to leave comments, you need to log in
How to insert image in pyqt5?
you need to insert an image in the window. everywhere shows the same way
label = QLabel(self)
pixmap = QPixmap('image.jpeg')
label.setPixmap(pixmap)
import sys
from PyQt5 import QtWidgets, QtGui
class Window(QtWidgets.QWidget):
def __init__(self, ):
super().__init__()
self.resize(800, 600)
self.center()
self.general()
def general(self, ):
# Menu Bar
self.lbl = QtWidgets.QLabel(self)
self.pix = QtGui.QPixmap("img.png")
print(self.pix.isNull())
self.lbl.setPixmap(self.pix)
self.lbl.resize(500, 500)
self.lbl.move(50, 50)
self.show()
def center(self, ):
frame_window = self.frameGeometry()
center_coord = QtWidgets.QDesktopWidget().availableGeometry().center()
frame_window.moveCenter(center_coord)
self.move(frame_window.topLeft())
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
According to code:
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
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_())
This is how it works tested
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("ёлка.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_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question