Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望能够从给定的文件夹中一张一张地加载大量图像。而且也不知道每个图像的名称(只有所有图像所在的文件夹的名称)。目前我只能使用它的名称(pic.jpg)加载一张图片:
pixmap = QtGui.QPixmap("pic.jpg") item = QtGui.QGraphicsPixmapItem(pixmap) self.scene.addItem(item) self.scene.update()
有没有办法做到这一点?提前致谢!
os 模块包含文件系统访问函数。
import os dir = "dirname" for file in os.listdir(dir): ... = QtGui.QPixmap(os.path.join(dir, file))
注意: os.path.join 在那里,因此您与平台无关。