How do I get screen size locally?

OS (e.g. Win10): Win11
PsychoPy version (e.g. 1.84.x): v2024.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I’m hoping to get the window sizes in pixels at the beginning of the experiments and store them for later use.

What did you try to make it work?:
I looked at the Window documentation and tried what other people suggested in some previous discussions. For example:
screenWidth=psychopy.visual.window.size[0]
or

win = psychopy.visual.Window
screenWidth=win.size[0]

But nothing seems to work.

What specifically went wrong when you tried that?:
I get
AttributeError: module 'psychopy.visual.window' has no attribute 'size'
when I run this
screenWidth=psychopy.visual.window.size[0]

and I get
TypeError: 'property' object is not subscriptable
when I run

win = psychopy.visual.Window
screenWidth=win.size[0]

Thank you!!

Which tab is your code in? My guess is that it will fail in Before Experiment and potentially be wrong in Begin Experiment. I normally put it in End Routine of the first routine, unless I just want to know whether the screen is in portrait or landscape mode in which case Begin Experiment is fine.

Thank you for the reply! I tried Before Experiment, Begin Experiment and End Routine but none of them worked. I get the same error no matter which tab the code goes. Are there other ways to get the window sizes?

Delete this line

win = psychopy.visual.Window

That worked perfectly! Thank you!!