Python and Pycharm with PyQt5 Library: Showing up a picture

Viewed 71

i want to build app with pyqt5 in python but i got some error while running it i tried to solved it but i cant because im newbie to this

i want to show the picture there are 1 frame, 1 button while pressing button on gui that i made from designer pyqt5-tools the picture shown up on frame.

here is my code and where is my fault, can you fix it?

import sys
import cv2
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QImage,QPixmap
from PyQt5.QtWidgets import QDialog,QApplication,QMainWindow,QLabel
from uic import loadUi

class ShowImage (QMainWindow):
    def __init__(self):
        super(ShowImage,self).__init__()
        loadUi('GUI.ui',self)
        self.image=None
        self.loadButton.clicked.connect(self.loadClicked)
        @pyqtSlot()
        def loadClicked(self):
            self.loadImage('smarthealth.jpg')
    def loadImage(self,img="smarthealth.jpg"):
        self.image=cv2.imread(img)
        self.displayImage()
    def displayImage(self):
        qformat=QImage.Format_Indexed8
        if len(self.image.shape)== 3:
            if (self.image.shape[2])== 4:
                qformat=QImage.Format_RGBA8888
        else:
                qformat=QImage.Format_RGB888
        img=QImage(self.image,self.image.shape[1],self.image.shape[0],
                   self.image.strides[0],qformat)
        img = img.rgbSwapped()
        self.imgLabel.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt
                               .AlignVCenter)
app=QtWidgets.QApplication(sys.argv)
window= ShowImage()
window.setWindowTitle('Show Image GUI')
window.show()
sys.exit(app.exec())
0 Answers
Related