本文介绍了在pyqt上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在pyqt中显示图像以用于我的课程.我正在处理问题"子例程中尝试此操作.这是一个示例
I'm trying to display an image in pyqt for my coursework. I'm attempting this in the Handle Question sub routine. here's a sample of it
class IntegrationQuestions(QtGui.QMainWindow):
def __init__(self, parent = None):
from equation import IntQuestion, IntAnswer
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('Simple Integration')
self.setMinimumSize(265,400)
self.lbl1 = QtGui.QLabel("Integrate the equation below",self)
self.lbl1.move(0,0)
self.lbl1.resize(200,20)
self.lbl2 = QtGui.QLabel(pretty(IntQuestion[0], use_unicode = False), self)
self.lbl2.resize(200, 80)
self.lbl2.move(30,30)
self.lbl3 = QtGui.QLabel("Sketch pad",self)
self.lbl3.move(0,120)
self.SketchPad = QtGui.QLineEdit(self)
self.SketchPad.resize(250,150)
self.SketchPad.move(0,150)
self.lbl4 = QtGui.QLabel("Answer",self)
self.lbl4.move(0,300)
self.Answer = QtGui.QLineEdit(self)
self.Answer.move(0,330)
self.Answer.resize(250,20)
self.next_question.clicked.connect(self.HandleQuestion)
这是我尝试添加问题的地方
def HandleQuestion(self):
pic = QtGui.QLabel(self)
pic.setPixmap(QtGui.QPixmap("Q107.png"))
self.lbl3.move(0,190)
self.SketchPad.resize(250,80)
self.SketchPad.move(0,220)
推荐答案
您已正确初始化了所有内容,但从未设置要显示的标签.
You initialized everything properly, however you never set the label to be shown.
def HandleQuestion(self):
pic = QtGui.QLabel(self)
pic.setPixmap(QtGui.QPixmap("Q107.png"))
pic.show() # You were missing this.
self.lbl3.move(0,190)
self.SketchPad.resize(250,80)
self.SketchPad.move(0,220)
这篇关于在pyqt上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!