0

我希望能够从给定的文件夹中一张一张地加载大量图像。而且也不知道每个图像的名称(只有所有图像所在的文件夹的名称)。目前我只能使用它的名称(pic.jpg)加载一张图片:

pixmap = QtGui.QPixmap("pic.jpg")
item = QtGui.QGraphicsPixmapItem(pixmap)
self.scene.addItem(item)
self.scene.update()

有没有办法做到这一点?提前致谢!

4

1 回答 1

1

os 模块包含文件系统访问函数。

import os
dir = "dirname"
for file in os.listdir(dir):
    ... = QtGui.QPixmap(os.path.join(dir, file))

注意: os.path.join 在那里,因此您与平台无关。

于 2013-10-15T08:35:10.450 回答