【发布时间】:2019-02-17 17:53:04
【问题描述】:
我是 PyQt 编程新手,当我运行此代码然后按下按钮时,窗口总是没有响应。
第二个问题我如何在按下按钮时在标签中加载图像,我花了 3 个小时来得到一个问题但我没有得到答案:(( 在我的英语不好之前如何解决它和抱歉
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
from PyQt5.uic import loadUi
class ShowImage (QMainWindow):
def __init__(self):
super(ShowImage,self).__init__()
loadUi('ganteng.ui',self)
self.image=None
self.loadButton.clicked.connect(self.loadClicked)
@pyqtSlot()
def loadClicked(self):
self.loadImage('2.jpg',cv2.IMREAD_GRAYSCALE)
def loadImage(self,Flname):
self.image=cv2.imread(flname)
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.serPixmap (QPixmap.fromImage(img))
self.imgLabel.setAlignment (qtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
app=QtWidgets.QApplication(sys.argv)
window=ShowImage()
window.setWindowTitle('gambar')
window.show()
app.exec_()
【问题讨论】:
-
到处都是错别字:将
Flname更改为flname,serPixmap更改为setPixmap,qtCore更改为QtCore
标签: python python-3.x pyqt5