1
我想在PyQT中使用filepicker在GUI中顯示圖像。到目前爲止,我設法打開圖像文件,但完全混淆瞭如何在GUI中顯示圖像。如何在PyQT GUI中顯示圖像?
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(100, 100, 500, 300)
self.setWindowTitle("PyQT Show Image")
openFile = QtGui.QAction("&File", self)
openFile.setShortcut("Ctrl+O")
openFile.setStatusTip("Open File")
openFile.triggered.connect(self.file_open)
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(openFile)
self.home()
def home(self):
self.show()
def file_open(self):
name = QtGui.QFileDialog.getOpenFileName(self, 'Open File')
file = open(name, 'r')
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()
請在這裏指導我如何在GUI中顯示圖像。謝謝
Thanks Controlix –