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

标签 python user-interface fullscreen psychopy

我想使用 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)

最佳答案

这是因为当 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)

中途显示对话框

如果你想在实验中途显示对话,你需要一个非常复杂的技巧。你需要

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

关于python - 为什么当 fullscr=True 时我的对话框不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30544209/

相关文章:

python - 我可以连接到另一台服务器上的mysql数据库吗?

objective-c - 如何为 QuickLook 插件开发/创建 GUI?

Java 全屏模式不适用于 Ubuntu

android - 如何彻底退出沉浸式全屏模式?

python - matplotlib fill_ Between 显示点

python - 从 CSV 文件创建图形并使用 Django 和 Pandas Python 库呈现到浏览器

java - 来自另一个类的 RadioButton setText

linux - 使用 MacOS、Linux 和 Windows 的 SVN

html - 浏览器全屏的 Bootstrap 模式问题

python - 使用 SQLAlchemy 导入的 Postgresql 数据将 JSON 转换为 Python Dict