How to have parts of a TextStim displayed in italics

1,007 views
Skip to first unread message

Elise DG

unread,
Dec 2, 2015, 3:48:27 PM12/2/15
to psychopy-users
Hi there,

I am totally new to Python and psychopy and just starting to put together an experiment on psychopy 1.83.01, mainly using the builder but inserting code here and there to fullfil my needs.

I am trying to have an item of a questionnaire displayed to user in which some words are in italic font.
Is it possible? And if yes, how?

I must have missed something very trivial here, sorry for asking if this is the case.

Thanks in advance for your help.
Best

Elise


Jeremy Gray

unread,
Dec 2, 2015, 3:51:57 PM12/2/15
to psychop...@googlegroups.com
Hi Elise,

Welcome to PsychoPy.

I am totally new to Python and psychopy and just starting to put together an experiment on psychopy 1.83.01, mainly using the builder but inserting code here and there to fullfil my needs.

I am trying to have an item of a questionnaire displayed to user in which some words are in italic font.
Is it possible? And if yes, how?

Sorry no, its not possible to arrange for this easily. Nor different font, color, bold, etc. One way is to have separate textstim for the different parts of the sentence, and format each of those how you want, and arrange for them to appear in the right places on the screen. Another way is to format your text in some other program, capture a screenshot, and display the images from within PsychoPy.

--Jeremy 

Michael MacAskill

unread,
Dec 2, 2015, 5:30:18 PM12/2/15
to <psychopy-users@googlegroups.com>

> On 3/12/2015, at 09:51, Jeremy Gray <jrg...@gmail.com> wrote:
>
> Sorry no, its not possible to arrange for this easily. Nor different font, color, bold, etc.

Is this supposed to be possible using Sol's TextBox class?

I tried to check, but unfortunately, when running the various TextBox demos, they all yield an "AttributeError: 'module' object has no attribute 'textbox'" error. (In both the current Mac standalone and a development installation).

Looking in the psychopy/visual hierarchy, TextBox is the only stimulus that has a folder rather than a "textbox.py" file at the top level, with the class definition found inside the __init__.py file within that folder.

Is it just me, or is this class not able to be imported correctly?

Regards,

Michael



Jeremy Gray

unread,
Dec 2, 2015, 6:02:58 PM12/2/15
to psychop...@googlegroups.com
I too get an error. It goes away if I change visual.__init__.py to use an absolute import:

from psychopy.visual.textbox import TextBox

This is within the lazyImports section. 

The TODO.txt file suggests that its not yet possible to set things like italics on a pre-character basis.

--Jeremy




--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/408B1DC5-998B-434B-A3B3-ABEB937BDCD4%40nzbri.org.
For more options, visit https://groups.google.com/d/optout.

Michael MacAskill

unread,
Dec 2, 2015, 7:37:33 PM12/2/15
to <psychopy-users@googlegroups.com>

> On 3/12/2015, at 12:02, Jeremy Gray <jrg...@gmail.com> wrote:
>
> I too get an error. It goes away if I change visual.__init__.py to use an absolute import:
>
> from psychopy.visual.textbox import TextBox
>
> This is within the lazyImports section.
Ahh, OK, this makes sense based on your earlier message today on the developer list: just followed the links you posted there, as I wasn't really au fait with any of those import distinctions.

> The TODO.txt file suggests that its not yet possible to set things like italics on a pre-character basis.

Ahh, OK, so no solution there for Elise (as yet…)

Thanks,

Mike


--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Elise DG

unread,
Dec 3, 2015, 2:05:41 AM12/3/15
to psychopy-users
Hi Jeremy and Mike,

Thank you for your quick answer!

I will try as you suggest with screenshots...I am sure it works...

Alternatively, I thought about also having something like 3 TextStim defined that are a) "Beginning of sentence", b) "part in italics", c) "End of sentence" and to concatenate them into a string variable like FullSentence = Beginning + Italic Part + End of sentence.
Then I would display $FullSentence in another TextStim. Would that have a chance to work? And if yes, what would be the code for concatenating strings into a single variable?

Thanks again for your help and time.
Best

Elise

Jeremy Gray

unread,
Dec 3, 2015, 6:25:46 AM12/3/15
to psychop...@googlegroups.com
I will try as you suggest with screenshots...I am sure it works...

Alternatively, I thought about also having something like 3 TextStim defined that are a) "Beginning of sentence", b) "part in italics", c) "End of sentence" and to concatenate them into a string variable like FullSentence = Beginning + Italic Part + End of sentence.
Then I would display $FullSentence in another TextStim. Would that have a chance to work? And if yes, what would be the code for concatenating strings into a single variable?

This will not work. Concatenating strings is super easy (just: a = b + c), but concatenating /formatted/ strings is not.

--Jeremy

 

Thanks again for your help and time.
Best

Elise

On Thursday, December 3, 2015 at 1:37:33 AM UTC+1, michael.macaskill wrote:

> On 3/12/2015, at 12:02, Jeremy Gray <jrg...@gmail.com> wrote:
>
> I too get an error. It goes away if I change visual.__init__.py to use an absolute import:
>
> from psychopy.visual.textbox import TextBox
>
> This is within the lazyImports section.
Ahh, OK, this makes sense based on your earlier message today on the developer list: just followed the links you posted there, as I wasn't really au fait with any of those import distinctions.

> The TODO.txt file suggests that its not yet possible to set things like italics on a pre-character basis.

Ahh, OK, so no solution there for Elise (as yet…)

Thanks,

Mike


--
Michael R. MacAskill, PhD                66 Stewart St
Research Director,                        Christchurch 8011
New Zealand Brain Research Institute        NEW ZEALAND

Senior Research Fellow,                        michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi        Ph:   +64 3 3786 072
University of Otago, Christchurch        http://www.nzbri.org/macaskill

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

Elise DG

unread,
Dec 3, 2015, 8:21:13 AM12/3/15
to psychopy-users
That's a shame! But never mind.
I have a working exp now with screenshots of sentence with italic parts and that does the trick.

Thank you again for your help on this!
Best

Elise
Reply all
Reply to author
Forward
0 new messages