Using Image Stimuli to pull in Images defined from Excel

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2022.1.2
Standard Standalone? (y/n) If not then what?: Y

What are you trying to achieve?:

Hi everyone,

I am trying to build an experiment that uses images that are pre-determined from an Excel file. So in the experiment, there will be two images that are seen one after another(image 1 - 500 ms, ISI - 100 ms, image 2 - 500ms). In total, there will be around 40 images so I do not want to have to manually define each image stimuli in the Builder. I would like to be able to use an Excel file and have the code randomly select the image. I have attached screenshots of how the Builder looks and how I have things programmed.

What did you try to make it work?:

I watched the following video and tried to do exactly what they did here:

Here is what the image stimuli looks like. Image 1 and Image 2 are the same with different names to indicate different columns from Excel:

Here is what the Loop variable looks like:

image

Here is what the Excel file looks like:

image

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

This is the error message produced in the Runner tab:

Traceback (most recent call last):
File “C:\Users\James\Downloads\training\Learning_lastrun.py”, line 349, in
Image1.setImage(Image1)
AttributeError: ‘str’ object has no attribute ‘setImage’
################ Experiment ended with exit code 1 [pid:12584] #################
879.7952 INFO Loaded monitor calibration from [‘2022_03_16 17:35’]

Overall, I am not sure where I am going wrong. Any help is greatly appreciated, and if there is anything I can do to explain further, please let me know.

Thank you!
James

In a computer program, you can’t use the same name to refer to two different things. e.g. the names Image1 for your Builder image component and Image1 as the name of a column in your Excel file are in conflict, so one overwrites the other.

Simply change the names in your Excel file to something distinct, e.g. Image1_filename and Image2_filename, and edit the “Image” fields of your components to correspond to the new names.

Hi Michael,

Thank you very much! The code works perfectly now :smiley:

James

James,

I am taking a shot in the dark here, but would you be willing to send me this study? I have a similar (structurally) idea in mind and I’m struggling with the basics of Psychopy. I think your framework here would help me off the ground. No worries if not :slight_smile:

Thanks!
David