pyqt5通过文本对话框打开文件

时间:2022-08-15 22:59:31

点击按钮,打开文本对话框,找一人文件,打开并显示内容                                                                                                                                                                                     

                                                                                                                                                                                              QFIleDialog

pyqt5通过文本对话框打开文件                                                                 pyqt5通过文本对话框打开文件

def openfile(self):
filename,_
= QFileDialog.getOpenFileName(self);
text
=open(filename,'r').read()
self.textEdit.setText(text)

我用QFile,QTextStream,QIODevice做了半天也没做出来,改用python自带的文件操作命令做了出来。