| Reference | Downloads | Github

PsychoPy equivalent of DrawFormattedText in PTB

Hello PsychoPy community!

I am fairly new to coding up experiments for data acquisition and due to the rest of my lab’s experience with MATLAB and PsychToolBox, I ended up coding my first paradigm using these tools during my pilot sessions. The code works, but it is ugly and I would much prefer to use Python as I have much more experience with it. I have checked out compatibility with EyeLink, which PsychoPy seems to have, as well as all the other standard things such as interfacing with LabJacks etc.

The one thing I would definitely need is something comparable to PsychToolBox’s “DrawFormattedText” function, which returns the on-screen coordinates of the boxes around all individual words on the screen at a particular moment in time.

If PsychoPy offers a function like this, I will immediately jump over to PsychoPy and happily forget using PTB due to its awkwardness (at least for someone who feels much more comfortable with Python). However, the closest thing I could find was in TextStim, that there is a boundingBox method, but this seems to only give the bounding box of the text as a whole, and not also as an array of each individual word (which PTB does provide).

I hope this functionality is hidden somewhere else or has previously been implemented as some sort of add on? Is anyone aware of whether this is possible (easily) in PsychoPy?


Alex M

If you are prepared to use a monospaced font, you could calculate the coordinates of individual words by simply dividing the bounding box of the text stimulus into chunks based on the number of letters in each word and the spaces between words.