# The loop displays a series of images

**URL:** <https://discourse.psychopy.org/t/the-loop-displays-a-series-of-images/19352>\
**Category:** Builder\
**Tags:** randomization\
**Created:** [January 4, 2021, 1:16pm UTC](https://discourse.psychopy.org/t/the-loop-displays-a-series-of-images/19352 "2021-01-04T13:16:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayang](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Ayang](https://discourse.psychopy.org/u/Ayang)\
**Post date:** [January 4, 2021, 1:16pm UTC](https://discourse.psychopy.org/t/the-loop-displays-a-series-of-images/19352/1 "2021-01-04T13:16:26Z")

</div>

**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 😊

**What did you try to make it work?:**

```auto
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)

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/a/ba9adea8416bd615c49d08bad15f546190e617cb.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/8/a8a01fa61ee2d81ac28a5987b28cbd3339594fa9.png)

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

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [January 6, 2021, 10:26am UTC](https://discourse.psychopy.org/t/the-loop-displays-a-series-of-images/19352/2 "2021-01-06T10:26:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ayang](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Ayang](https://discourse.psychopy.org/u/Ayang)\
**Post date:** [January 8, 2021, 6:53am UTC](https://discourse.psychopy.org/t/the-loop-displays-a-series-of-images/19352/3 "2021-01-08T06:53:24Z")

</div>

I’ve solved the problem, thanks ~ 😊
