我想要一个实验,显示一堆随机的点,然后要求用户输入他们看到的正确数量的点。我想让实验循环。我可以让它在1次迭代中工作,但是循环有问题,因为窗口和对话框发生冲突,或者窗口没有正确关闭。当前运行这个脚本时,gui会冻结。我用我的代码尝试了python3和python2。在
import random
import psychopy.visual
import psychopy.event
import psychopy.core
from psychopy import gui
import time
while True:
win = psychopy.visual.Window(
size=[500, 500],
units="pix",
fullscr=False
)
myDlg = gui.Dlg(title="Response")
n_dots = random.randint(5, 200)
dot_xys = []
for dot in range(n_dots):
dot_x = random.uniform(-250, 250)
dot_y = random.uniform(-250, 250)
dot_xys.append([dot_x, dot_y])
dot_stim = psychopy.visual.ElementArrayStim(
win=win,
units="pix",
nElements=n_dots,
elementTex=None,
elementMask="circle",
xys=dot_xys,
sizes=10,
contrs=random.random(),
)
dot_stim.draw()
win.flip()
psychopy.event.clearEvents()
time.sleep(4)
win.close()
myDlg.addField('How many dots did you see?')
number = myDlg.show()
if myDlg.OK:
print(number)
myDlg.close()
psychopy.core.quit()
我用的是最新版本的神经病。如果你有什么建议,请告诉我。谢谢!在
通常,您不会使用对话框来收集响应。更确切地说,你可以用心理刺激来制作一些在窗户内工作的东西。这里有一个解决方案:
相关问题 更多 >
编程相关推荐