| Reference | Downloads | Github

Multiple Variables in Text Component

Hey guys,

I have many instructions for the experiment I am currently working on.
I wanted to present them all in one text component and therefore made a Loop around my text component with the following conditions-file:

Later I wanted to add more Text for Instr1 and Instr2 but currently I am already struggling with displaying the both texts beneath each other. I tried to do it this way:

unfortunately this does not work. I hope someone has an idea!
I am trying it this way, because I wanted to reduce the amount of text-components from 10 to 1 with a loop.

OS (Win10):
PsychoPy version (e.g. 1.90.1):
**Standard Standalone

Hello. In Builder, there is often a lot of confusion about the the $ symbol represents. It doesn’t mean “this is a variable name”. It means “Interpret what follows as valid Python syntax rather than literal text”. So you can combine variables, operate on them with Python functions, and do pretty much anything you want. For example, one of the simplest way to combine strings of characters in Python is simply to add one to another. In your case:

$Instr1 + '\n' + Instr2

(Notice there is just one $ required, at the beginning of the expression).
Here, \n is a special escape sequence, indicating a new line character.


Hey Micheal,

that perfectly worked for me, thank you!

Is it possible to use different font sizes for the different variables? For example, in Michael’s code, can Instr1 be a different size from Instr2?

Unfortunately no. Text stimuli are currently limited to a single font setting for all their content. To get this effect, you would need to create two separate text stimuli, with different font sizes applied to each as required.

1 Like