| Reference | Downloads | Github

How to present slider labels without ticks

OS: a) Win10 b) Ubuntu 18.04
PsychoPy version: a) 3.15 b) 3.20
Standard Standalone?: a) y b) installed from wheel into system python
What are you trying to achieve?: Manipulate position of ticks/labels in slider component

What did you try to make it work? Tried to insert custom component

What specifically went wrong when you tried that? Commands are ignored

I want to obtain ratings through a slider, where the slider line has delimiters at both ends, but no ticks inbetween, even though there are five labels distributed along the line to provide some orientation.
I used ticks at 0 and 1 and inserted the following custom code into “Begin Routine”:
‘’‘Evaluation_4.labelLocs = [0.1, 0.3, 0.5, 0.7, 0.9]’’’
Evaluation_4 is the name of the slider component. This was ignored, though. The labels were all placed below the two ticks at 0 or 1.
I also tried it the other way round, i.e. I first entered many tick positions in builder and then tried to override them with custom code defining just the two end ticks, but that had no effect either.
So given that a code component can achieve what I want, how should it look?

Hi @Detlef, you could achieve the same thing using a slider type of Slider (see Appearance tab in Slider component dialog box). Change to appearance of slider, with white on black appearance. This gives a slider with no tick locations. Alternatively, you could use the following in a code component, in the “Begin Routine” tab (same routine as the Slider):

for i, line in enumerate(slider.tickLines.sizes):
    if i not in [0,4]:  # Where 0 and 4 are your first and last tick locations
        slider.tickLines.sizes[i][1] = 0
slider.tickLines._needVertexUpdate = True

The code does exactly what I wanted. I had thought of shrinking some ticks to zero height but no clue how to access their size properties. Many thanks not only for the solution but also for the immediate response. Could you elaborate on that _needVertexUpdate? When and why is it required?

_needVertexUpdate tells the Slider components that it has to send updated size information (vertices) to the graphics card for drawing. Without this, the old sizes as vertices are not overwritten in the calls to draw the Slider, and so you will only see the old tick sizes, even though the sizes were changed. Hope that helps.