如下所示:
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_())
以上这篇Python 使用PyQt5 完成选择文件或目录的对话框方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 金池VS刘罡2009《双声情》[WAV+CUE]
- 冯奥迪《卄》[320K/MP3][67.08MB]
- 冯奥迪《卄》[FLAC/分轨][172.46MB]
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]