简体   繁体   中英

How to load multiple images from folder. PyQt4

I want to be able to load large number of images one by one from the given folder. And also without knowing the names of the each image (only the name of the folder where all images are located). Currently I can load only one image using it's name (pic.jpg):

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

Is there any way to do this? Thanks in advance!

The os module contains filesystem access functions.

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

Note: os.path.join is there so you are platform agnostic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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