Error : "deg" when drawing Scaler

I found the following code for creating and drawing a scaler.

from psychopy.visual.window import Window
from psychopy.visual.slider import Slider

mywin = Window()

vection_scale = Slider(mywin,
             ticks=(1, 100),
             labels=('No Vection', 'Strong Vection'),
             granularity=1,
             color='white',
             size = (0.99,0.05))

while not vection_scale.rating:
    vection_scale.draw()
    mywin.flip()

vection_rating = vection_scale.rating
RT_rating = vection_scale.rt
print(vection_rating,RT_rating)

print(f'Rating: {vection_scale.rating}, RT: {vection_scale.rt}')

mywin.close()

The code works perfectly when mywin = Window() - when I do not put arguments to the window function.

After integrating this piece of code in my experiment code, with my window specification as shown below :

#Monitor settings
widthPix = 1400 # screen width in px
heightPix = 900 # screen height in px
monitorwidth = 53.1 # monitor width in cm
viewdist = 60. # viewing distance in cm
monitorname = 'BOE CQ LCD'
scrn = 0 # 0 to use main screen, 1 to use external screen
mon = monitors.Monitor(monitorname, width=monitorwidth, distance=viewdist)
mon.setSizePix((widthPix, heightPix))

# Create a window
win = psychopy.visual.Window(
    monitor=mon, 
    #size=(1000, 800),
    size=(widthPix,heightPix),
    color='Black',
    colorSpace='rgb',
    units='deg',
    screen=scrn,
    allowGUI=True,
    fullscr=False)

I get this error. The problem is that I need units = 'deg' to draw my stimuli.


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-ebcaf2ecf00b> in <module>
    117 # ---------------------------------------- Create Scale to Rate Feeling of Vection ------------------------------------------------------------------------
    118 
--> 119 vection_scale = Slider(win,ticks=(1, 100),labels=('No Vection', 'Strong Vection'),granularity=1,color='white')
    120 
    121 # ----------------------------------------- Start Experiment ------------------------------------------------------------------------------------

~/opt/anaconda3/lib/python3.7/site-packages/psychopy/visual/slider.py in __init__(self, win, ticks, labels, pos, size, units, flip, style, granularity, readOnly, color, font, depth, name, labelHeight, labelWrapWidth, autoDraw, autoLog)
    140 
    141         if size is None:
--> 142             self._size = defaultSizes[self.units]
    143         else:
    144             self._size = size

KeyError: 'deg'

How can I overcome this obstacle? thanks in advance for your help :slight_smile:

Hi Kathia,

I see the problem looking in the code - basically when you draw a Slider without specifying its size, it looks up the Window's units in a dictionary called defaultSizes to find what size to set it to by default. Currently, this dictionary only has values for 'norm':

defaultSizes = {'norm': [1.0, 0.1]}

I’ll add some more presets for the next release, but for the time being you should be able to get around this bug by specifying a size for your Slider so that it doesn’t have to check for defaults.

Thanks,

Todd

Thanks @TParsons for your answer!

I have tried to add a window size as follows:

vas = Slider(win,
             ticks=(1, 100),
             labels=('Not at all confident', 'Extremely confident'),
             granularity=1,
             color='white',
             size = [1.0, 0.1])

and I got this error:

ValueError: Monitor __blank__ has no known size in pixels (SEE MONITOR CENTER)

That looks like a problem with your monitor configuration, what do you have set up currently in the Monitor Center?

I used the following settings:


#Monitor settings
widthPix = 1920 # screen width in px
heightPix = 1080 # screen height in px
monitorwidth = 53.1 # monitor width in cm
viewdist = 60. # viewing distance in cm
monitorname = 'BOE CQ LCD'
scrn = 0 # 0 to use main screen, 1 to use external screen
mon = monitors.Monitor(monitorname, width=monitorwidth, distance=viewdist)
mon.setSizePix((widthPix, heightPix))

# Create a window
win = psychopy.visual.Window(
    monitor=mon, 
    size=(1080, 608),
    #size=(widthPix,heightPix),
    color='Black',
    colorSpace='rgb',
    units='deg',
    screen=scrn,
    allowGUI=True,
    fullscr=False)

I am using a different size in win size=(1080, 608) while I am programming, but the final outcome will use the size=(widthPix,heightPix)

Hey Kathia,

have you found a solution for this ValueError? I get the same one and don’t really know how to fix it as I’m completely new to PsychoPy.

Any helpful hint is appreciated! :slight_smile: