def open_file(self):
name=QFileDialog.getOpenFileName(self, 'Open File')
file=open(name, 'rb', encoding= 'utf8')
self.editor()
with file:
text=file.read()
self.textEdit.setText(text)
expected str, bytes or os.PathLike object, not tuple i got this error when i opened an image.
>Solution :
getOpenFileName return a tuple with the name and the extension
def open_file(self):
name = QFileDialog.getOpenFileName(self, 'Open File')
file = open(name[0], 'rb', encoding='utf8')
self.editor()
with file:
text = file.read()
self.textEdit.setText(text)
You should also make a test to see if you return something otherwise the program could crash
def open_file(self):
name = QFileDialog.getOpenFileName(self, 'Open File')
if name[0] == '':
return
file = open(name[0], 'rb', encoding='utf8')
self.editor()
with file:
text = file.read()
self.textEdit.setText(text)