在您的情况下,您缺少在标签中显示图片的代码行:
pixmap = QtGui.QPixmap(self.mainwindow_image).scaled(main_width, main_height, aspectRatioMode = 1)
self.label = QtWidgets.QLabel(self.widget_1)
self.label.setMinimumSize(QtCore.QSize(225, 200))
self.label.setMaximumSize(QtCore.QSize(225, 200))
self.label.setText("")
self.label.setObjectName("label")
self.label.setPixmap(pixmap)
由于您的代码不完整,我为您添加了 Qt 设计师 Mark Summers 计算的示例(更新的 pyqt5 样式),以从中学习(阅读:apyqt5 gui 的骨架结构)并应用上述标签代码。享受。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from math import *
from PyQt5 import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QAction, QApplication, QDialog, QLineEdit, QTextBrowser, QVBoxLayout, QWidget
#from PyQt5.QtGui import
class Form(QDialog):
def __init__(self, parent = None):
super(Form, self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Lots of text here... type something and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
# starts at the lineEdit for the user to type straight away.
self.setLayout(layout)
self.lineedit.setFocus()
self.lineedit.returnPressed.connect(self.updateUi)
self.setWindowTitle("Calculate the shit out of your CPU")
def updateUi(self):
try:
text = unicode(self.lineedit.text())
self.browser.append("%s = <b>%s<b/>" % (text, eval(text)))
except:
self.browser.append("<font color=red> %s is invalid!</font>" % text)
pass
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Form()
window.show()
sys.exit(app.exec_())