当fullscr = True时,为什么我的对话框不显示?

时间:2015-05-30 08:56:48

标签: python user-interface fullscreen psychopy

我想显示一个对话框,让实验参与者使用心理模型输入一个数字。当获胜时fullscr=False,将显示对话框。当fullscr=True时,它不会出现,即使键入数字然后返回确实会使程序进入下一个循环。

任何想法为什么?相关代码行如下。

from psychopy import visual, event, core, data, gui, logging
win = visual.Window([1024,768], fullscr=True, units='pix', autoLog=True)

respInfo={}
respInfo['duration']=''
respDlg = gui.DlgFromDict(respInfo)

1 个答案:

答案 0 :(得分:3)

这是因为在fullscr=True时心理窗口位于其他所有内容之上,因此在您的示例中,创建了对话框,但由于窗口位于顶部,因此用户无法看到该对话框。

开头的

对话框

如果您只想在实验开始时使用对话框,解决方案很简单:在创建窗口之前显示对话框:

# Import stuff
from psychopy import visual, gui

# Show dialogue box
respInfo={'duration': ''}
respDlg = gui.DlgFromDict(respInfo)

# Initiate window
win = visual.Window(fullscr=True)

中途出现对话框

如果你想在实验期间中途展示对话,你需要一个非常复杂的黑客攻击。你需要

  1. 关闭当前窗口,
  2. 显示对话框(可选择在后台使用非全屏窗口来覆盖桌面)
  3. 创建一个新窗口(并关闭步骤2中的可选窗口)
  4. 设置要在新窗口中渲染的所有刺激。由于刺激指向第一个窗口 object ,所以只创建一个具有相同变量名称的新窗口(新对象)将不起作用。
  5. 以下是一些使用单一刺激来演示此方法的代码:

    # Import stuff, create a window and a stimulus
    from psychopy import visual, event, gui
    win1 = visual.Window(fullscr=True)
    stim = visual.TextStim(win1)  # create stimulus in win1
    
    # Present the stimulus in window 1
    stim.draw()
    win1.flip()
    event.waitKeys()
    
    # Present dialogue box
    win_background = visual.Window(fullscr=False, size=[5000, 5000], allowGUI=False)  # optional: a temporary big window to hide the desktop/app to the participant
    win1.close()  # close window 1
    respDict = {'duration':''}
    gui.DlgFromDict(respDict)
    win_background.close()  # clean up the temporary background  
    
    # Create a new window and prepare the stimulus
    win2 = visual.Window(fullscr=True)
    stim.win = win2  # important: set the stimulus to the new window.
    stim.text = 'entered duration:' + respDict['duration']  # show what was entered
    
    # Show it!
    stim.draw()
    win2.flip()
    event.waitKeys() 
    
相关问题