The loop displays a series of images

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2020.2.10

What are you trying to achieve?:
HI ALL!
I want randomly select 10 pictures from a folder as stimulus, then I wrote the flowing codes with Code Component in the begin routine tab, but showing only one picture that the loop will finish.

How should I modify the codes, and all 10 pictures will appear on the screen.Thanks :blush:

What did you try to make it work?:

import os
import random

filenames= os.listdir('./pics/')
random.shuffle(filenames)
list_for_centers=filenames[:10]

for item in list_for_centers:
    target='./pics/'+item
    print(target)


What specifically went wrong when you tried that?:
Showing only one picture that the loop will finish.

Hi There!

Are you presenting images sequentially? If so, Please can I check why an inner loop is not appropriate for this? e.g. your outer loop is trials and your inner loop takes a .csv/.xlsx file with a list of your filenames in it?

Thanks,
Becca

I’ve solved the problem, thanks ~ :blush: