pyqt5 file_open 方法错误,打开图片时出现此错误

pyqt5 file_open method error, i got this error when i opened an image

 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)

应为 str、字节或 os.PathLike 对象,而不是元组 我在打开图像时收到此错误。

getOpenFileName return 包含名称和扩展名的元组

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)

你也应该做一个测试看看你是否return 否则程序可能会崩溃

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)