psychopy.org | Reference | Downloads | Github

Present text stimuli that contain umlauts (ä,ö,ü,ß)

Hello everyone,

I am trying to code a memory reaction task is which participants have to respond to a list of words that is presented on screen (one word at a time). The words that are presented contain ‘ä’,‘ö’,‘ü’ and ‘ß’. I am having trouble displaying these. I am using Psychopy 1.85.2 and can currently not switch to a newer version.
For simply displaying words I know I can use u’ , but I want to get the information from a variable that contains the whole list of words. I have tried different things, but it just keeps getting more confusing. For a code example that might be close to what I want, see the code below, which however results in the following error message:

objecttestword = generateText(u"’"+ target_words[test_word])
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xf6 in position 5: ordinal not in range(128)


#!/usr/bin/env python2
# -*- coding: utf-8 -*- 
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging

# Generate preformatted text
def generateText(text):
    return visual.TextStim(
    win, 
    color='#000000',
    text = text,
    units='norm', 
    height=0.05,
    pos=[0,0], 
    alignVert='center'
    )
    

# create arrays that hold the words that will appear on screen
target_words = [u'der Löwe', u'die Flöte']

# make fullscreen
win = visual.Window([1920,1200], monitor="testMonitor", units="norm", fullscr= True, color='#FFFFFF') #'fullscr=True' 
win.setMouseVisible(False)

## Create Memory Test
def doMemoryTest():
    instructionMemTest = generateText(u'Instruktionen')
    instructionMemTest.draw()
    win.flip()
    event.waitKeys('w')
    for test_word in range(len(target_words)):
        target_words[test_word] = target_words[test_word].encode('iso-8859-1')
        objecttestword = generateText(u"'"+ target_words[test_word])
        objecttestword.draw()
        win.flip()
        event.waitKeys('1' '2')


doMemoryTest()

Hi!
Your code worked on my machine (Psychopy 1.82) with some changes: Actually removing target_words[test_word] = target_words[test_word].encode(‘iso-8859-1’) solves the problem I think. (Also you might want to check the config of your computer).

# !/usr/bin/env python2
# -*- coding: utf-8 -*-
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging


# Generate preformatted text
def generateText(text):
    txt= visual.TextStim(
        win,
        color='#000000',
        text=u"",
        units='norm',
        height=0.05,
        pos=[0, 0],
        alignVert='center'
    )
    txt.setText(text)
    return txt


# create arrays that hold the words that will appear on screen
target_words = [u'der Löwe', u'die Flöte']

# make fullscreen
win = visual.Window([1920, 1200], monitor="testMonitor", units="norm", fullscr=True, color='#FFFFFF')  # 'fullscr=True'
win.setMouseVisible(False)


## Create Memory Test
def doMemoryTest():
    instructionMemTest = generateText(u'Instruktionen')
    instructionMemTest.draw()
    win.flip()
    event.waitKeys('w')
    for test_word in range(len(target_words)):
        print target_words[test_word]
        #target_words[test_word] = target_words[test_word].encode('iso-8859-1')
        objecttestword = generateText(target_words[test_word])
        objecttestword.draw()
        win.flip()
        event.waitKeys(['1','2'])


doMemoryTest()