gpt4 book ai didi

python - 带数字键盘的心理评级量表

转载 作者:行者123 更新时间:2023-12-01 04:45:07 25 4
gpt4 key购买 nike

在我的任务中,我一直允许使用数字键盘(例如“num_1”)以及键盘顶部的常规数字(例如“1”)进行响应。当我稍后使用 ratingScale 请求评级时,我希望这两个选项也可用,但我不知道如何实现这一点。

按原样, ratingScale 不接受使用数字键盘的响应。我可以使用 respKeys 更改此设置,但我必须提供“用于按所需顺序选择选项的键列表”。这意味着我不能允许“1”和“num_1”同时选择第一个评级(例如,使用 respKeys = ['1','num_1, '2', 'num_2', ...] '1' 将选择第一个评级,'num_1' 选择第二个评级,依此类推)。

我真的坚持使用 respKeys = ['1','2','3','4','5']respKeys = ['num_1', “num_2”、“num_3”、“num_4”、“num_5”]

感谢您的帮助!

最佳答案

我认为 visual.RatingScale 没有任何内置方法可以为同一刻度位置采用多个键盘键。

如果您使用编码器,则可以使用 event.getKeys()visual.RatingScale.setMarkerPos()。因此,对于具有三个位置的评级量表的简单情况:

# Initiate psychopy stuff
from psychopy import visual, event
win = visual.Window()
scale = visual.RatingScale(win, low=1, high=3)

# A list of lists, each sublist being the keys which represents this location
keysLocation = [['1', 'num_1'], ['2', 'num_2'], ['3', 'num_3']]
respKeys = [key for keysLoc in keysLocation for key in keysLoc] # looks complicated but it simply flattens the list to be non-nested

# Present the ratingscale and wait for a response
currentPos = 1
while scale.noResponse:
response = event.getKeys(keyList=respKeys) # only accept respKeys
if response and response[0] in respKeys:
# Then loop through sublists and update currentPos to where the match is
for i, loc in enumerate(keysLocation):
if response[0] in loc:
currentPos = i

# Set the marker position and draw
scale.setMarkerPos(currentPos)
scale.draw()
win.flip()

我的解决方案看起来很复杂,但大部分只是处理 keysLocation 列表并搜索匹配项。很抱歉变量名称不好/不明确,但我现在想不出更好的方法。

此解决方案可能也适用于 Builder。只需删除“启动psychopy”内容,将scale更改为您的RatingScale的名称,然后将代码粘贴到RatingScale正上方的代码组件中即可。

关于python - 带数字键盘的心理评级量表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29635920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com