TypeError: unsupported operand type(s) for -: 'str' and 'float'

An experiment that was running successfully in PsychoPy 2020.1.2, was then loaded in 2020.2.4, and compiled and run there. The screen went blank for a moment, and then the experiment exited abruptly. The Runner did not capture any error output. The only way to see that is to rerun the experiment manually on the command line: >python experimentname_lastrun.py

This produced a traceback ending with:

    pal['lineRGB'] = pal['lineColor'] = [max(c - 0.05, 0.05) for c in self.win.color]
TypeError: unsupported operand type(s) for -: 'str' and 'float'

Not very useful, but this was generated by a Form component in the experiment, and after some debugging, turned out to be due to an experiment setting.

To fix, go to Experiment Settings > Screen > Color, and change “black” to “$[0,0,0]”. The documentation indicates that named colors are supported, so this is either a new bug, or the documentation is outdated, but maybe this helps someone.

As the Form component is still in Beta, this is one of the new features which needs smoothing out - that code essentially darkens the border of a textbox when it’s selected. It does so by subtracting a value from each RGB value of the Window’s colour, which it can’t do when the Window’s colour is set by name (it’s essentially saying “subtract 0.05 from the letter ‘b’”). I’m currently working on some changes to how colours are handled by Psychopy which will fix this in the next release - it will treat colours as objects rather than values, allowing us to define methods for adding and subtracting from them like this which won’t be dependent on colour space.

In the meantime I think you’ve got the right solution - Window colour will have to be specified in RGB when using Form components.