Here is some code that does what you and @erelender described:
import os,sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
window.setGeometry(0, 0, 400, 200)
pic = QtGui.QLabel(window)
pic.setGeometry(10, 10, 400, 100)
#use full ABSOLUTE path to the image, not relative
pic.setPixmap(QtGui.QPixmap(os.getcwd() + "/logo.png"))
window.show()
sys.exit(app.exec_())
A generic QWidget
does not have setPixmap()
. If this approach does not work for you, you can look at making your own custom widget that derives from QWidget
and override the paintEvent
method to display the image.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…