我正在尝试为我的毕业论文复制心理学实验。我对psychopy和python编码很新。通过我的在线搜索,我设法为我的实验添加输入文本功能。但是有一个小问题:当参与者输入答案时,文本有时不会被包裹并超出屏幕。我将文本包装在组件对话框中,但它不起作用。使输入文本功能成为可能的代码如下:
inputText = ""
cursorCounter=0
cursorVariable='|'
theseKeys=""
shift_flag = False
text_3.alignHoriz ='left'`
if cursorCounter >= 30:
if cursorVariable=='|':
cursorVariable=' '
else:
cursorVariable='|'
cursorCounter=0
cursorCounter+=1
n= len(theseKeys)
i = 0
while i < n:
if theseKeys[i] == 'return' and len(inputText) > 4:
# pressing RETURN means time to stop
continueRoutine = False
break
elif theseKeys[i] == 'backspace':
inputText = inputText[:-1] # lose the final character
i = i + 1
elif theseKeys[i] == 'space':
inputText += ' '
i = i + 1
elif theseKeys[i] in ['lshift', 'rshift']:
shift_flag = True
i = i + 1
elif theseKeys[i] == 'period':
inputText = inputText + "."
i = i + 1
elif theseKeys[i] == 'comma':
inputText = inputText + ","
i = i + 1
else:
if len(theseKeys[i]) == 1:
# we only have 1 char so should be a normal key,
# otherwise it might be 'ctrl' or similar so ignore it
if shift_flag:
inputText += chr( ord(theseKeys[i]) - ord(' '))
shift_flag = False
else:
inputText += theseKeys[i]
i = i + 1
inputText = inputText.capitalize()
# let's store the final text string into the results finle...
thisExp.addData('inputText', inputText)
inputText=""
还有一个小问题,当输入的文本太大时,它也会向上移动并与问题上方的其他文本重叠。我相信这些都是简单的问题,但不幸的是我缺乏修复它们的知识。如果你能帮助我,我会很高兴的!