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?
‘$efflabels’ does not work either… It gives the error:
Traceback (most recent call last):
File "E:\PsyTest\Efftest_lastrun.py", line 93, in <module>
flip=False, depth=0)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\contrib\lazy_import.py", line 120, in __call__
return obj(*args, **kwargs)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\slider.py", 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(",")
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.
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
There were my last issues (after post 4 with version 2021.1.2) :
and
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?
I’ve seen several posts asking how to update slider labels each repeat. None of them worked for me, but I found a solution now (in Standalone PsychoPy, didn’t try online yet). Thanks TParsons for the valuable input!
Didn’t use Excel file but instead defined labels in Code Component.
Version: v2023.2.3
System: Windows 11
Setup: Routine has at least Slider component and Code component.
Example with two repeats, 3 labels each. For Slider Component in labels field: 1,2,3
In “Begin Routine” tab of the Code component:
labels = [["Yes", "No", "Maybe"], ["Poor ", "Medium", "Great"]]
# Determine the set of labels based on the current repeat index
current_labels = labels[myLoop.thisN % len(labels)]
# Reset the slider to update labels
mySlider.reset()
# 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
if i < len(current_labels):
obj.text = mySlider.labels[i] = current_labels[i]
May not be the most elegant but seems to work. Only: In Auto->JS it says “/* Syntax Error: Fix Python code */”. Any idea why and how to fix it?