Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Importing all images from folder into one list

Obligatory - I am new to coding.

I am creating a canvas in an inline script and would would like to import about 70 images from a folder on my computer into a list, which I can then shuffle. The goal is to place a random selection of the 70 images onto the canvas by selecting a few positions from the list. Unfortunately, it seems like the lists i create do not match the required formatting.

I have tried to solve this by using recommendations from similar problems on stack overflow, which resulted in something like this:


Unfortunately, this results in the error message:

TypeError: target is not a canvas element but <class 'PIL.PngImagePlugin.PngImageFile'>


Does anyone know how I could try and solve this error?

Thanks

Comments

  • Hi @Annarasumanara ,

    You're using PIL.Image.open() to read the images. This is a function from the PIL library and results in a special kind of object that OpenSesame doesn't recognize. To read an image as a canvas element, you need to use the Image() function (see here), which is a built-in function in OpenSesame. In your case, you simply need to replace:

    stimuli_list = [Image.open(item) …]
    

    By:

    stimuli_list = [Image(item) …]
    

    Hope this helps!

    — Sebastiaan

Sign In or Register to comment.