There is not a magic keypress that will always work for closing a window or escaping from a process. I highly recommend developing your experiment with fullscr=False, and then changing to fullscr=True in the final stages and for running subjects. (This switch is in Builder > Experiment settings > Screen > Full-screen Window -- uncheck to box, or the fullscr=False parameter when creating a Window instance in code.) Its much easier to switch back and forth and close zombie windows if you are not in full-screen mode.
In the Builder, the 'escape' key often will work like a magic key, but only because some code generated by the Builder specifically listens for the 'escape' key and will bail out if it gets one. (Compile a Builder script and check out the code!). Note that there is an Experiment setting which allows you to disable escape, so even this is not guaranteed to work.
From the Coder, if you make a 2-line program like this and run, it will shut the window itself when it ends:
from psychopy import visual
w = visual.Window()
Putting core.quit()
somewhere in the code will have the same effect as the script ending at the end (i.e., the window will close down fine).
If you have a window already created, you can close it without quitting PsychoPy, but you have to know how to refer to that window instance and tell it to close() -- w1
in the example below:
from psychopy import visual
w1 = visual.Window()
w1.close()
# do other things here, perhaps a GUI
w2 = visual.Window() # another, new window pops open
Multiple windows closing and reopening is not common usage--if you find yourself doing it, there's probably a better way. But it does illustrate how to close a window.