如下所示:
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 fil

本文展示了如何在Python中使用PyQt5库创建一个GUI界面,该界面包含一个菜单项,用户可以通过点击它来打开一个文件或目录选择对话框。当用户选择一个文件后,其内容将显示在文本编辑器中。如果文件打开失败,界面会显示错误信息。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



