繁体   English   中英

Python PyQt5:如何通过QFileDialog获取图像文件的名称和内容

[英]Python PyQt5: How to get the name and the content of an image file by QFileDialog

如何使用QFileDialog打开图像文件? 我也想知道如何获取文件的名称,例如,图像文件名为“ photo.png”,我想打印其名称。

def openImage(self):
    fileName = QFileDialog(self)
    fileName.getOpenFileName()
    image = QImage(fileName)
    print(fileName.FileName)

我自己解决问题:

def openImage(self):
    fileName = QFileDialog().getOpenFileName()
    filePath = str(fileName[0])

    image = QImage(filePath)

    label = QLabel()
    label.setPixmap(QPixmap().fromImage(image))

    self.addWidget(label, 0, 0)

    fileObject = filePath.split('/')
    file = fileObject[ len(fileObject) - 1 ]
    print(file)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM