如下所示:

import sys
from PyQt5.QtWidgets import QMainWindow,QApplication,QTextEdit,QAction,QFileDialog
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.textEdit = QTextEdit()
self.setCentralWidget(self.textEdit)
self.statusBar()
openfile = QAction(QIcon(r'C:\Users\Administrator\PycharmProjects\QT\picture\文件.jpg'),'open',self)
openfile.setShortcut("Ctrl + 0")
openfile.setStatusTip('open new file')
openfile.triggered.connect(self.showDialog)
menubar = self.menuBar()
filemune = menubar.addMenu('$File')
filemune.addAction(openfile)
self.setGeometry(300,300,300,300)
self.setWindowTitle('FIEL dialog')
self.show()
def showDialog(self):
fname = QFileDialog.getOpenFileName(self,'open file', '/')
if fname[0]:
try:
f = open(fname[0], 'r')
with f:
data = f.read()
self.textEdit.setText(data)
except:
self.textEdit.setText("打开文件失败,可能是文件内型错误")
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。