How to set slider values to variable from .xlsx?

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.10
What are you trying to achieve?:

→ set slider values to a variable from .xlsx file

I want to assign different slider labels for different questions, using a radio slider. This way I can ask different questions with different answer options without making a massive experiment (with so many flows that it becomes very slow…). I cannot figure out how I can let PsychoPy ‘read’ the slider value labels from an excel file. Is this not possible?

What did you try to make it work?:

$efflabels does not work

‘$efflabels’ does not work either… It gives the error:

Traceback (most recent call last):
  File "E:\PsyTest\", line 93, in <module>
    flip=False, depth=0)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\contrib\", line 120, in __call__
    return obj(*args, **kwargs)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\", line 174, in __init__
    self.labelHeight = labelHeight or min(self._size)
TypeError: 'float' object is not iterable
##### Experiment ended. #####

The problem is that efflabels will be read as a string - so you need to split it up into a list. I would remove the brackets from the Excel file and then set the value of labels to be $efflabels.split(",")

Thank you for your reply!

I tried this, but it gives the error:

    labels=[$efflabels.split(",")], ticks=(1, 2, 3),
SyntaxError: invalid syntax
##### Experiment ended. #####

Split it in code and then use the new list in the component


Delete the dollar?

Ah, the $ being printed is a problem fixed in 2021.1.x - so if you’re able to (and I’d advise making a copy of your study before opening it again in 2021) then updating should fix this.

Is there any way to do this in the 2020.2.10 version? I had some issues with sliders in the 2021.1.1 version so I am a bit afraid of using that again, as it might introduce new problems.

Deleting the dollar did not work :frowning:

How would I go about splitting it in code and using the new list in the component? I do not quite understand.

Setting labels after initialisation is difficult, but not impossible! If you have the same number of labels each time, you could do this:

# Get labels list for this routine
labels = efflabels.split(",")
# For each label...
for i, obj in enumerate(mySlider.labelObjs):
    # ...set its text to be the corresponding value in labels, and store this in the slider
    obj.text = mySlider.labels[i] = labels[i]

(the initial value of labels would need to be the same number of values as in efflabels separated by commas, what these values are is basically irrelevant)

Updating is still the cleanest way though, what issues are you having? If a bug in the new release makes you not want to update then that’s something I’m keen to fix

1 Like

Thank you very much for your help!

There were my last issues (after post 4 with version 2021.1.2) :


If this is not an issue anymore or if there is something I can do to fix it, what version would you recommend me to download? PsychoPy 2021.1.3 ? Or an older one?

Thank you very much in advance!