问题
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)
回答1:
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.
Present dialogue box in the beginning
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
- close your current window,
- show the dialogue box (optionally with a non-fullscreen window in the background to cover up your desktop)
- create a new window (and close the optional window from step 2
- 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()
来源:https://stackoverflow.com/questions/30544209/why-does-my-dialogue-box-not-show-when-fullscr-true