Firstly, this is just a general Python error: you are trying to refer to a variable (
win) that has never been defined, so Python simply doesn’t know what to do with it. The same thing would have happened if you didn’t have a line defining
noise_rc as having the value 1 before you attempted to use it when creating the grating stimulus.
In PsychoPy specific terms,
win is just a common variable name for referring to the window you want to draw into. There is nothing magical about that variable name, you could call it anything you want (
participant_window, etc). In PsychoPy code, many of us just commonly use the name
win because it is short and we all know what it means. But whatever you call it, it needs to be defined before you try to use it.
Just check any PsychoPy example script. Near the top, not long after the import lines, will be a line that looks like this:
win = visual.Window() # now you have a window to actually draw into.
In the Coder view, check out the Demos menu. There are many useful example scripts available there that show how to display stimuli, get keypresses, control timing, and so on. Good luck with learning the ropes.