| Reference | Downloads | Github

Use of slider.noResponse - lack of a demo


I realize the slider is still in active development, however I can’t seem to get the new
slider to work.

Ideally I would use the it for it’s .noResponse functionality
like so:

import psychopy.visual
display_resolution = 1024,768
window = psychopy.visual.Window(display_resolution,fullscr=False,units='pix',allowGUI=False)
my_slider = psychopy.visual.Slider(window,units='pix')

while my_slider.noResponse:

Traceback (most recent call last):
  File "C:\Python27\Anaconda\lib\site-packages\IPython\core\", line 2878, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-6876aeda903d>", line 4, in <module>
    my_slider = psychopy.visual.Slider(window,units="pix")
  File "C:\Python27\Anaconda\lib\site-packages\psychopy\contrib\", line 120, in __call__
    return obj(*args, **kwargs)
  File "C:\Python27\Anaconda\lib\site-packages\psychopy\visual\", line 146, in __init__
    self._size = defaultSizes[self.units]
KeyError: 'pix'

Win10, psychopy v. 3.0.0b7

It says in the documentation that there should be examples at the
Coder Demos → stimuli →

However I don’t see it here:

Best Regards

Ah! that documentation is outdated, copied from RatingScale. And, yes, I didn’t get around to adding the demo for Coder yet (there is one for Builder called ratingsNew)

The equivalent code now would be:

while not my_slider.rating:

For any object you can see what’s possible by doing print(dir(something)) so, in your case you could do print(dir(my_slider)) to find the correct options.

Note that there’s also another attribute called my_slider.markerPos that indicates (or can set) the current value of a rating scale before it has been confirmed. e.g. while the marker is being dragged the markerPos will update, and when the mouse is released it will be copied over to my_slider.rating

Thanks! for the quick reply

Thanks for the tip on print(dir(my_slider)) and
The while loop works!, (it helped me isolate the problem further)

The core problem, was that for some reason Slider does not accept specification of units=, either units=pix or units=deg, or when it is inherited from window. Or perhaps my python/psychopy is a bit rusty?


# Works!
from psychopy import visual

window = visual.Window((1024,768),fullscr=False,allowGUI=False)
my_slider = visual.Slider(window) # <- unspecified units
my_text = visual.TextStim(window,units="pix")

# Does not work - how I normally use it

window = visual.Window((1024,768),fullscr=False,allowGUI=False,units="pix")
my_slider = visual.Slider(window)
my_text = visual.TextStim(window)

# Does not work
window = visual.Window((1024,768),fullscr=False,allowGUI=False)
my_slider = visual.Slider(window,units="pix")
my_text = visual.TextStim(window,units="pix")

Just a style comment, unrelated to your question: you could probably standardise your imports here to get more consistent/concise/readable code. e.g.

from psychopy import visual

win       = visual.Window()
my_slider = visual.Slider(win)
my_text   = visual.TextStim(win)
# etc

rather than sometimes working from the psychopy module level and sometimes from a particular class like slider.

ah yeah sure, my python is a bit rusty

I am having the same issue with units. Did you resolve this?

@BronteMckeown, the ability to control Slider units from the Slider dialog box was included in the latest release of PsychoPy (try 3.2.3). You can either upgrade your current version, or go to Experiment Settings > Use Version and select the version you require.