Building a questionaire, with likert scale resoponse from excel

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2023.2.23
Standard Standalone? (y/n) Y
What are you trying to achieve?:

Hi there,

I’m trying to build a questionaire with a 1-4 point likert scale response. Answers include ‘Highly curious’, ‘Slightly curious’, ‘Barely curious’, 'Not at all curious.

I’d like to do this from a loop so I can attatch an excel spreadsheet where each row is another piece of text which someone will rate their curiousty about.

I’d like to record these responses.

What did you try to make it work?:

I have inserted a routine which has a code component and a text componet. The text component has $question_text set to ‘every repeat’.

The following code is in the Begin Routine phase:

from psychopy import visual, event as evt, core, gui
import pandas as pd

Load your spreadsheet

survey_data = pd.read_excel(‘Study_1_trivia.xlsx’)

Initialize PsychoPy window

win = visual.Window()

Iterate over survey questions

for index, row in survey_data.iterrows():
question_text = row[‘question_text’]

# Create text stimulus for the question
question_stim = visual.TextStim(win, text=question_text)

# Draw the question
question_stim.draw()
win.flip()

# Wait for response
rating_scale = visual.RatingScale(win, low=1, high=4, markerStart=2, labels=['Not at all curious', 'Somewhat curious', 'Slightly curious', 'Highly curious'], scale='How curious are you to know the answer?', pos=(0, -0.4), textSize=0.5, lineColor='black', textColor='white')
while rating_scale.noResponse:
    rating_scale.draw()
    win.flip()

# Get response
response = rating_scale.getRating()

# Print or save the response
print("Response to question {}: {}".format(index + 1, response))

Close the window

win.close()

What specifically went wrong when you tried that?:

UnboundLocalError: local variable ‘visual’ referenced before assignment