# Display a random image in multiple locations at once

**URL:** <https://discourse.psychopy.org/t/display-a-random-image-in-multiple-locations-at-once/41186>\
**Category:** Coding\
**Created:** [August 27, 2024, 5:59pm UTC](https://discourse.psychopy.org/t/display-a-random-image-in-multiple-locations-at-once/41186 "2024-08-27T17:59:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![lilih](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/lilih/32/45927_2.png) [@lilih](https://discourse.psychopy.org/u/lilih)\
**Post date:** [August 27, 2024, 8:49pm UTC](https://discourse.psychopy.org/t/display-a-random-image-in-multiple-locations-at-once/41186/2 "2024-08-27T20:49:36Z")

</div>

Hi!

I have a small update, but unfortunately the project is still unsuccessful at the moment. I found

> [@Method to copy a visual object?](https://discourse.psychopy.org/t/method-to-copy-a-visual-object/25813):
>
> At initialization I wish to create a visual.ImageStim with a certain pos as such stim = visual.ImageStim(WIN, # capitalized variables are global const image=os.path.join(STIMULI\_PATH, filename + '.png'), pos = LEFT\_POS ) I also wish to place this same image at other locations. I would create an array to hold these stimuli with the different locations and then loop through them to draw them later. However, the following of course does not work as the position of…

I think this is closer to what I am looking for, however, when I tried to do something similar, I get an ‘invalid operation’ error. Here is my current code:

```auto
im = random.choice(imList)
        nIms = random.randint(3, 7)
        

        # positions
        pos1 = [-750, 0]
        pos2 = [-650, 0]
        pos3 = [-550, 0]
        pos4 = [-450, 0]
        pos5 = [-350, 0]
        pos6 = [-250, 0]
        pos7 = [-150, 0]
        
        if nIms == 3: 
            for pos in [pos1, pos2, pos3]: 
                im.pos = pos
        elif nIms == 4: 
            for pos in [pos1, pos2, pos3, pos4]: 
                im.pos = pos
        elif nIms == 5: 
            for pos in [pos1, pos2, pos3, pos4, pos5]: 
                im.pos = pos
        elif nIms == 6: 
            for pos in [pos1, pos2, pos3, pos4, pos5, pos6]: 
                im.pos = pos
        elif nIms == 7: 
            for pos in [pos1, pos2, pos3, pos4, pos5, pos6, pos7]: 
                im.pos = pos

        im.draw(); win.flip(); core.wait(1)

```

As a reminder, im is a variable that randomly selected a hard coded image from a list. The images on that list have no assigned position yet. I hope to display a random image a random number of times in different coded positions across the screen. I think the forum linked in this update is close to what I want to do, but if anyone spots anything off with my code, please let me know!

Thank you!

---

_[View the full topic](https://discourse.psychopy.org/t/display-a-random-image-in-multiple-locations-at-once/41186)._
