我正在为我的毕业论文复制一个心理学实验。我对神经病和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=""
还有一个小问题,当输入的文本太大时,它也会向上移动并与问题上方的其他文本重叠。我相信这些都是简单的问题,但不幸的是,我缺乏解决这些问题的知识。如果你能帮我,我会很高兴的!在
目前没有回答
相关问题 更多 >
编程相关推荐