【问题标题】:Why does my dialogue box not show when fullscr=True?为什么当 fullscr=True 时我的对话框不显示?
【发布时间】:2015-05-30 08:56:48
【问题描述】:

我想显示一个对话框,让实验参与者输入一个数字,使用psychopy。当fullscr=False 在win 中时,显示对话框。当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)

【问题讨论】:

    标签: python user-interface fullscreen psychopy


    【解决方案1】:

    这是因为当fullscr=True 时,psychopy 窗口位于其他所有内容之上,因此在您的示例中,对话框已创建但对用户不可见,因为该窗口位于顶部。

    在开头显示对话框

    如果你在实验开始时只想要一个对话框,解决方法很简单:在创建窗口之前显示对话框:

    # Import stuff
    from psychopy import visual, gui
    
    # Show dialogue box
    respInfo={'duration': ''}
    respDlg = gui.DlgFromDict(respInfo)
    
    # Initiate window
    win = visual.Window(fullscr=True)
    

    中途显示对话框

    如果你想在实验过程中显示对话,你需要一个相当复杂的 hack。你需要

    1. 关闭当前窗口,
    2. 显示对话框(可选择在背景中使用非全屏窗口来覆盖您的桌面)
    3. 创建一个新窗口(并关闭第 2 步中的可选窗口
    4. 设置所有刺激物在新窗口中呈现。由于刺激指向第一个窗口对象,因此仅创建一个具有相同变量名称的新窗口(新对象)是行不通的。

    这里有一些代码通过单个刺激来演示这种方法:

    # 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() 
    

    【讨论】:

    • 知道这一点很有用,谢谢。但是,我已经在屏幕上显示了一条消息,因此已创建并显示了窗口:我需要在每个试验例程的中途出现对话框。那么我先fullscr=False,然后显示对话框然后返回fullscr=True,这有意义吗?
    • 啊,有趣的问题。我用可能的解决方案更新了答案。我敢肯定它没有你希望的那么干净,但至少它有效:-)
    猜你喜欢
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 2018-02-13
    相关资源
    最近更新 更多