我已经编写了下面的代码,并访问了许多教程/网站,以了解如何显示图像。下面的代码似乎运行没有错误,但没有显示任何内容?映像文件与python代码文件位于同一目录中。图像文件是名为' hello'
的PNG图像守则如下所示:
import sys, math, random, os
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
layout = QtGui.QVBoxLayout(self)
pic = QtGui.QLabel(self)
pic.setGeometry(10, 10, 400, 100)
#use full ABSOLUTE path to the image, not relative
pic.setPixmap(QtGui.QPixmap(os.getcwd() + "C:\\Users\\Hamzah\\My Documents\\Work\\A-Level\\USB Stuff\\Coding For Project Starter/hello.png"))
layout.addWidget(pic)
self.setLayout(layout)
if __name__ == "__main__":
app = QtGui.QApplication([])
window = Window()
window.showFullScreen()
app.exec_()