为什么当fullscr = True时我的对话框没有显示? [英] Why does my dialogue box not show when fullscr=True?

查看:110
本文介绍了为什么当fullscr = True时我的对话框没有显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个对话框,要求实验参与者使用心理测验输入数字.赢得fullscr=False时,将显示对话框.当fullscr=True时,即使键入数字然后返回,它也不会出现,但会使程序前进到下一个循环.

I want to display a dialogue box to ask an experimental participant to enter a number, using psychopy. When fullscr=False in win, the dialogue box displays. When fullscr=True, it doesn't appear, even though typing the number and then return does progress the program to the next loop.

任何想法为何?下面的相关代码行.

Any ideas why? Relevant code lines below.

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)

推荐答案

这是因为当fullscr=True时,心理窗口位于所有其他内容的顶部,因此在您的示例中,对话框被创建但由于该窗口位于顶部而对用户不可见.

This is because the psychopy window is on top of everything else when fullscr=True so in your example, the dialogue box is created but not visible to the user since the window is on top.

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

If you just want a dialogue box in the beginning of the experiment, the solution is easy: show the dialogue box before creating the window:

# Import stuff
from psychopy import visual, gui

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

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

当前对话框中途

如果您想在实验过程中显示对话,则需要一个复杂的技巧.您需要

Present dialogue box mid-way

You need a pretty convoluted hack if you want to show a dialogue midway during the experiment. You need to

  1. 关闭当前窗口,
  2. 显示对话框(可以选择在后台使用非全屏窗口来掩盖您的桌面)
  3. 创建一个新窗口(并关闭第2步中的可选窗口
  4. 设置所有要在新窗口中呈现的刺激.由于刺激指向第一个窗口 object ,因此仅创建一个具有相同变量名的新窗口(新对象)就不会成功.
  1. close your current window,
  2. show the dialogue box (optionally with a non-fullscreen window in the background to cover up your desktop)
  3. create a new window (and close the optional window from step 2
  4. set all stimuli to be rendered in the new window. Since the stimuli are pointing to the first window object, just creating a new window (new object) with the same variable name won't do the trick.

这里有一些代码通过一次刺激演示了这种方法:

Here's some code that demos this approach with a single stimulus:

# 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 = True时我的对话框没有显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆