AttributeError: 'NoneType' object has no attribute 'setMovie'

I’m new to PsychoPy and I’m using the v2023.1.2 with a combination of builder with snippets of code.

I have a routine called outcomes that has two text components and two video components. The routine outcomes is presented after a routine trial, which includes a key_resp that stores all answers and check for a correct response in a column named ‘correct’ in an Excel sheet. I have the two video and two text because they are differentially positioned in the screen (bottom or up), and I want to half of the trials present the video above the text and half of the trials present the text above the video; but every time just one text & one video should be presented. The video & text presented depend on the correct answer, so I have a code that reads from the Excel sheet correct column and if the answer was correct it shows LM_text and video1, whereas if it wasn’t it shows HM_text and video2. This is the code that I’m using:

In the before experiment tab:

from psychopy.sound import Sound

In the begin experiment tab:

correct_symbol = None
symbol_number = None
text_money1 = None
text_money2 = None
video_pain1 = None
video_pain2 = None

In the begin routine tab:

if symbol_number == '1':
    if trial_num % 2 == 0:  # Display text above video
    else:  # Display video above text
elif symbol_number == '2':
    if trial_num % 2 == 0:  # Display text above video
    else:  # Display video above text
    print('Invalid correct symbol.')

print('Correct Symbol:', correct_symbol)
print('Text 1:', text_money1)
print('Video 1:', video_pain1)
print('Text 2:', text_money2)
print('Video 2:', video_pain2)

the error is: AttributeError: ‘NoneType’ object has no attribute ‘setMovie’, which comes from video_pain2.setMovie(row[‘video1’]). I know this error means that instead of an instance of whatever video, I’ve actually got None. I don’t know how to solve the issue.

Additionall -in case it matters-, I really don’t care about the sound of the video, I just want it to be displayed and played automatically once, while simultaniously showing the text either above or below the video.

Any help would be appreciated! I can also send the PyschoPy and Excel files if that helps.

Thank you!


Assuming you have MovieStim objects named video_pain1 and video_pain2 in your routine in the builder, the most likely issue is that you set them as “None” in your begin experiment code, which doesn’t just clear the movie file they refer to, but the MovieStim objects themselves. Or, for some other reason, the MovieStim objects with those names have not been initialized when you call “SetMovie”.

I’m guessing you have that “begin experiment” code to make it so that they don’t appear on trials when you don’t want them? I’m going to recommend a much simpler solution that will require a little restructuring: Have only one text object and one video object, set their content on every repeat, and set their position on every repeat as well. In other word you can have columns for text_y and movie_y in your condition file and just set the “position” parameter of the text and movie objects to that in the builder, and not use any code at all. Or use setPos() in your code, if that’s easier given the rest of the setup for your experiment. Basically, it’s easier to change the parameters of one object rather than having two objects ant turning one ‘off’.

Hi Jonathan!

Thank you for your answer! Indeed it was much better to use just one object and indeed use the argument pos. However, I still had some problems displaying the video so in the end I moved everything to code, as it was easier for me to debug what was going wrong.

Thanks :slight_smile: