psychopy.org | Reference | Downloads | Github

Drawing a border around TextStim?

In Coder, is there some way to draw a border around a TextStim after it’s been created? I have two TextStim on the page indicating the two possible responses the participant can make, and I want a border to appear around the option chosen by the participant.

Hope that makes sense—thanks in advance for your help!

Yes, you can just use a Rect stimulus (http://www.psychopy.org/api/visual/rect.html#psychopy.visual.Rect).

If the contents of your text stimuli change from trial to trial, then you can use the boundingBox attribute of your text stimulus to update the size of the rectangle as required (http://www.psychopy.org/api/visual/textstim.html).

2 Likes

Thank you, that works great! Just to clarify: I placed a Rect stimulus below my TextStim, but is there another way to place text inside the Rect stimulus?

I’m not really sure what the issue is? i.e. Just give the rect stimulus the same location as the text stimulus, and the same size ( or scaled slightly larger), and it should appear as desired (i.e. the text will appear inside the rectangle).

Perhaps I’ve misunderstood something, so perhaps post a diagram of the current result and what you want to achieve…

1 Like

Oops, sorry for being unclear! I was just wondering whether it was possible to draw a single “Text Box” stimulus, like a TextStim that can also have a border and a background, instead of drawing two separate stimuli on top of one another. But draw a Rect and TextStim separately works well. Thanks again!